Skip to content

Commit

Permalink
refactor: use include function instead of tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny committed Dec 3, 2024
1 parent c1d9b18 commit 9079d6c
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions docs/4-Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ _Example:_
<head>
<meta charset="utf-8">
[...]
{%- include 'partials/metatags.html.twig' ~%}
{{- include('partials/metatags.html.twig') ~}}
</head>
<body>
[...]
Expand Down Expand Up @@ -352,7 +352,7 @@ social:
If needed, `title` and `image` can be overridden:

```twig
{% include 'partials/metatags.html.twig' with {title: 'Custom title', image: og_image} %}
{{ include('partials/metatags.html.twig', {title: 'Custom title', image: og_image}) }}
```

:::
Expand Down
2 changes: 1 addition & 1 deletion resources/layouts/_default/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</article>
{%- endfor ~%}
<footer>
{%- include 'partials/paginator.html.twig' with {'page': page} only ~%}
{{- include('partials/paginator.html.twig', {page}, with_context = false) ~}}
</footer>
</article>
{%- endblock content ~%}
6 changes: 3 additions & 3 deletions resources/layouts/_default/page.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" media="(prefers-color-scheme: light)" content="white" />
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="black" />
{%- include 'partials/metatags.html.twig' with {page, site} only ~%}
{{- include('partials/metatags.html.twig', {page, site}, with_context = false) ~}}
<style>{% apply minify_css %}
{%- include 'partials/new.css.twig' ~%}
{{- include('partials/new.css.twig') ~}}
/* new.css enhancements */
:root body > header {
--nc-lk-1: #006be9;
Expand Down Expand Up @@ -153,7 +153,7 @@
<a href="{{ url(site.home) }}">{{ site.title }}</a>
</div>
{%- endif ~%}
{%- include 'partials/navigation.html.twig' with {menu: site.menus.main} only ~%}
{{- include('partials/navigation.html.twig', {menu: site.menus.main}, with_context = false) ~}}
{%- endblock header ~%}
</header>
<main>
Expand Down
4 changes: 2 additions & 2 deletions resources/layouts/_default/page.json.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"data": [
{% if items is defined %}
{% for item in items %}
{% include 'partials/data.json.twig' with {'item': item} only %}{% if not loop.last %},{% endif ~%}
{{ include('partials/data.json.twig', {item: item}, with_context = false) }}{% if not loop.last %},{% endif ~%}
{% endfor %}
{% else %}
{% include 'partials/data.json.twig' with {'item': page} only -%}
{{ include('partials/data.json.twig', {item: page}, with_context = false) -}}
{% endif %}
]
{#- meta #}
Expand Down
2 changes: 1 addition & 1 deletion resources/layouts/partials/feeds-from-section.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{%- if page.section|default and page.type == 'page' -%}
{%- set section_page = site.page(page.section)|default -%}
{%- if section_page and section_page.alternates is defined -%}
{%- include 'partials/alternates.html.twig' with {'title': section_page.title|e ~ ' - ' ~ site.title|e , 'page': section_page, 'alternates': section_page.alternates|filter(a => a.format in feed_formats)} only ~%}
{{- include('partials/alternates.html.twig', {title: section_page.title|e ~ ' - ' ~ site.title|e , page: section_page, alternates: section_page.alternates|filter(a => a.format in feed_formats)}, with_context = false) ~}}
{%- endif -%}
{%- endif -%}
8 changes: 4 additions & 4 deletions resources/layouts/partials/metatags.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@
<link rel="last" href="{{ url(page.paginator.links.last, {'canonical': true}) }}" />
{%- endif -%}
{#- template: alternates ~#}
{%- include 'partials/alternates.html.twig' with {'title': title, 'page': page} only ~%}
{%- include 'partials/feeds-from-section.html.twig' with {'title': title, 'page': page} only ~%}
{{- include('partials/alternates.html.twig', {title, page}, with_context = false) ~}}
{{- include('partials/feeds-from-section.html.twig', {title, page}, with_context = false) ~}}
{#- template: alternates languages ~#}
{%- include 'partials/alternates-languages.html.twig' with {'page': page} only ~%}
{{- include('partials/alternates-languages.html.twig', {page}, with_context = false) ~}}
{#- template: preload ~#}
{%- if video_asset is defined ~%}
<link rel="preload" href="{{ url(video_asset) }}" as="video" type="{{ video_asset.subtype }}" />
Expand Down Expand Up @@ -242,5 +242,5 @@
<meta name="fediverse:creator" content="{{ mastodon.creator }}" />
{%- endif ~%}
{#- template: json-ld ~#}
{%- include 'partials/jsonld.js.twig' with {'author': author, 'favicon_asset': favicon_asset|default} ~%}
{{- include('partials/jsonld.js.twig', {author, favicon_asset: favicon_asset|default}) ~}}
{%- endblock ~%}
2 changes: 1 addition & 1 deletion resources/skeleton/layouts/blog/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</article>
{%- endfor ~%}
<footer>
{%- include 'partials/paginator.html.twig' with {'page': page} only ~%}
{{- include('partials/paginator.html.twig', {page}, with_context = false) ~}}
</footer>
</article>
{%- endblock content ~%}
4 changes: 2 additions & 2 deletions resources/skeleton/layouts/blog/page.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</header>
{{ page.content }}
<footer>
{%- include 'partials/terms-list.html.twig' with {'page': page, 'vocabulary': 'tags'} only ~%}
{%- include 'partials/page-navigation.html.twig' with {'page': page} only ~%}
{{- include('partials/terms-list.html.twig', {page, vocabulary: 'tags'}, with_context = false) ~}}
{{- include('partials/page-navigation.html.twig', {page}, with_context = false) ~}}
</footer>
</article>
{%- endblock content ~%}
2 changes: 1 addition & 1 deletion tests/fixtures/website/layouts/episodes/page.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

{% block content %}
{{ parent() }}
{% include 'partials/audioplayer.html.twig' %}
{{ include('partials/audioplayer.html.twig') }}
{% endblock %}
2 changes: 1 addition & 1 deletion tests/fixtures/website/layouts/shortcode.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

{% block content %}
{# page.content #}
{% include page.content_template %}
{{ include(page.content_template) }}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<summary>All pages</summary>
<ul>
{% for item in site.pages|sort_by_title %}
{% include 'includes/page_li.html.twig' %}
{{ include('includes/page_li.html.twig') }}
{% endfor %}
</ul>
</details>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

{% block content %}
{# page.content #}
{% include page.content_template %}
{{ include(page.content_template) }}
{% endblock %}

0 comments on commit 9079d6c

Please sign in to comment.