github.com/rabbouni145/gg@v0.47.1/docs/content/en/functions/GetPage.md (about)

     1  ---
     2  title: .GetPage
     3  description: "Gets a `Page` of a given `path`."
     4  godocref:
     5  date: 2017-02-01
     6  publishdate: 2017-02-01
     7  lastmod: 2017-02-01
     8  categories: [functions]
     9  menu:
    10    docs:
    11      parent: "functions"
    12  keywords: [sections,lists,indexes]
    13  signature: [".GetPage PATH"]
    14  workson: []
    15  hugoversion:
    16  relatedfuncs: []
    17  deprecated: false
    18  aliases: []
    19  ---
    20  
    21  `.GetPage` returns a page of a given `path`. Both `Site` and `Page` implements this method. The `Page` variant will, if given a relative path -- i.e. a path without a leading `/` -- try look for the page relative to the current page.
    22  
    23  {{% note %}}
    24  **Note:** We overhauled and simplified the `.GetPage` API in Hugo 0.45. Before that you needed to provide a `Kind` attribute in addition to the path, e.g. `{{ .Site.GetPage "section" "blog" }}`. This will still work, but is now superflous.
    25  {{% /note %}}
    26  
    27  
    28  ```go-html-template
    29  {{ with .Site.GetPage "/blog" }}{{ .Title }}{{ end }}
    30  ```
    31  
    32  This method wil return `nil` when no page could be found, so the above will not print anything if the blog section is not found.
    33  
    34  To fund a regular page in the blog section::
    35  
    36  ```go-html-template
    37  {{ with .Site.GetPage "/blog/my-post.md" }}{{ .Title }}{{ end }}
    38  ```
    39  
    40  And since `Page` also provides a `.GetPage` method, the above is the same as:
    41  
    42  ```go-html-template
    43  {{ with .Site.GetPage "/blog" }}
    44  {{ with .GetPage "my-post.md" }}{{ .Title }}{{ end }}
    45  {{ end }}
    46  ```
    47  
    48  ## .GetPage and Multilingual Sites
    49  
    50  The previous examples have used the full content filename to lookup the post. Depending on how you have organized your content (whether you have the language code in the file name or not, e.g. `my-post.en.md`), you may want to do the lookup without extension. This will get you the current language's version of the page:
    51  
    52  ```go-html-template
    53  {{ with .Site.GetPage "/blog/my-post" }}{{ .Title }}{{ end }}
    54  ```
    55  
    56  ## .GetPage Example
    57  
    58  This code snippet---in the form of a [partial template][partials]---allows you to do the following:
    59  
    60  1. Grab the index object of your `tags` [taxonomy][].
    61  2. Assign this object to a variable, `$t`
    62  3. Sort the terms associated with the taxonomy by popularity.
    63  4. Grab the top two most popular terms in the taxonomy (i.e., the two most popular tags assigned to content.
    64  
    65  {{< code file="grab-top-two-tags.html" >}}
    66  <ul class="most-popular-tags">
    67  {{ $t := .Site.GetPage "/tags" }}
    68  {{ range first 2 $t.Data.Terms.ByCount }}
    69      <li>{{ . }}</li>
    70  {{ end }}
    71  </ul>
    72  {{< /code >}}
    73  
    74  ## `.GetPage` on Page Bundles
    75  
    76  If the page retrieved by `.GetPage` is a [Leaf Bundle][leaf_bundle], and you
    77  need to get the nested _**page** resources_ in that, you will need to use the
    78  methods in `.Resources` as explained in the [Page Resources][page_resources]
    79  section.
    80  
    81  See the [Headless Bundle][headless_bundle] documentation for an example.
    82  
    83  
    84  [partials]: /templates/partials/
    85  [taxonomy]: /content-management/taxonomies/
    86  [page_kinds]: /templates/section-templates/#page-kinds
    87  [leaf_bundle]: /content-management/page-bundles/#leaf-bundles
    88  [headless_bundle]: /content-management/page-bundles/#headless-bundle
    89  [page_resources]: /content-management/page-resources/