We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [include]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
1answer
37 views

Using {% cache %} tags around {% template %} includes (or in Header)

I was wondering if it makes sense to wrap these {% cache %} around {% include %} tags that call a separate file with params. Is it better to just include them in the actual file itself? For example, ...
1
vote
2answers
27 views

Setting body ID from includes does not work

This is my _layouts/main.twig: <body {% if bodyId is defined %}id="{{ bodyId }}"{% endif %}> {% include '_layouts/header.twig' %} {% block main %} {% endblock %} </body> Then i ...
0
votes
1answer
54 views

Passing variables into twig components

Based on this interesting article: DRY templating with Twig and Craft CMS. I found myself trying to update the approach with include instead of macro following reading I had about twig 2 and craftcms ...
1
vote
1answer
68 views

Passing optional variable values into an include template

Craft noob here. I have an include file which I'm calling a "component" so I can reuse it across the site. The component is set up like this. <h2>{{ heading }}</h2> {{ bodyContent }} {% ...
2
votes
2answers
230 views

How to include twig in the editor? e.g. Shortcodes for dynamic content

I would like to display dynamic content in the middle of a text block. For example, a list of entries pulled in from the backend, in the middle of content. In Wordpress we can use Shortcodes. Does ...
1
vote
1answer
67 views

Get the variables of a loop from an include file

So my 1. file is "_overview-topicTeaser.twig" which is within a matrix: {% include 'modules/module-squareteaser/_module-squareteaser' with { squareTeasers: block.topicTeaserItems.all(), ...
1
vote
1answer
834 views

Twig function to load templates into variable?

I'm trying to figure out how to load a template file and pass it as a variable to another template file while it is being included. In some sense I want to do something like this: {% include '...
1
vote
1answer
475 views

Using a variable that was set in a previous include

By base.html: {% block searchLogic %} {% endblock %} {% block meetingDisplay %} {% endblock %} My index.html: {% extends "base.html" %} {% block ...
2
votes
1answer
19 views

How to slightly alter _layout for one specific page?

I have a _layout which includes a contact button: {% include '_contact-button' %} This creates a small contact button in the bottom right of every page that when clicked expands into a contact form. ...
1
vote
1answer
87 views

Use value of a dropdown field for an `include`

I'm trying to have this include be updated by the option I choose in my dropdown. {% include 'subnav_programs.html' %} My dropdown is called entry.dropSubsection I put {% include '{{ entry....
0
votes
2answers
1k views

Include with — variable does not exist error

New guy here. Can someone explain what the proper way to pass a variable into an include? I'm using this: {% include "singlepage" with { currentPage:'leaders' } %} .. and I'm getting a Variable "...
2
votes
2answers
54 views

Re-using includes when the object type changes (entry vs block) - what is the best method?

So I am trying to reuse some include files built for a matrix builder that are also in some instances used as stand alone fields (Video, Downloads etc). The way I have coded this is that the object/...
1
vote
0answers
79 views

Include with AJAX

I am fighting since days with this situation: I have a Select field with around 150 item and depending on a selected item a list of icons and names should be shown (around 50). The list of items (...
3
votes
1answer
904 views

Passing a variable to an include

I have a category listing template where I'm having trouble passing in some variables. top of the template I have this snippet where I'll set the channel and category field name based on the segment ...
1
vote
1answer
937 views

Use pure PHP and HTML instead of Templates

This is probably a very naive question but I am brand new to Craft and as such, have no idea what to research and where... I have a static website that is built with my own bespoke framework. We have ...
1
vote
1answer
469 views

How do I pass variables to loops within includes?

How do I pass variables to a loop within an include? This is my partial: {% for photo in photos %} <img src="{{ photo.projectPhotos_photo_image.first().getUrl('projectThumbnail') }}" {% ...
1
vote
1answer
157 views

Template Errors with Include on Single Entry

Now I've run into a really odd issue. I've got a hero include that is working elsewhere on the site, but on this one single it's not working at all. On a working "Single" the code is this {% extends "...
0
votes
2answers
119 views

Set Parent Template Defined Content to Output in Child Template

I have a layout template, we'll call that Template A that is extended by another template, we'll call that Template B that includes another template, we'll call that Template C that includes another ...
1
vote
1answer
145 views

Merging options to pass with an include

I'm trying to pull in the contents of a matrixField block and merge it with some default info — {% set interviews = craft.entries.section('interviews') %} {% for interview in interviews %} {% ...
1
vote
1answer
429 views

Use variable passed via include to set value of paramenter

I have an include setup for Navigation which works fine if I hard code in the level of the structure I want to use. However I need this to be set differently if the nav appears in the head or the ...
0
votes
1answer
742 views

Search in section only

How would I enable search in a single section only? I want my search results template to be used regardless of which search option is used. Ideally I'm looking to pass another value from my search ...
3
votes
1answer
4k views

Pass variable into include

I have a snippet within a template which I want to pass a variable into: page.twig {% set lightswitchTest = entry.aktivesProjekt('1').find() %} {% include '_snippets/thingy' %} thingy.twig <...
3
votes
1answer
320 views

search parameter passed to include

I have a template where I would like to pass a search parameter to a craft.entries.section in an included template. The current main template has this: {% include "_includes/testimonial" with { ...
4
votes
2answers
1k views

Newbie: Trying to understand includeCssFile

I'm a newbie to Craft and am working with a raw version of Craft CMS 2.6.2903 on localhost and am trying to understand some of the basics. The problem that I am encountering at the moment is to do ...
3
votes
1answer
3k views

Can I use a Block inside an Include file?

I have a _layout.html template which has both an include partial {% include '_partials/_header.html' %} and a block section (e.g. Content) for other templates to extend it. Can I put another block ...
12
votes
1answer
2k views

Macros vs Includes

Is there any guidance or pitfalls/benefits of using one over another? I see that includes can be done more or less the same way a Macro can be done (certainly for simple variable changes). An example ...
1
vote
1answer
275 views

Streamlining a loop with a bunch of conditions

I'm sure there must be a tidier and more efficient way of doing this so thought I'd throw it out there for some opinions. Building a site that has the usual lists (in grid format) for Blog, Gallery, ...
2
votes
1answer
1k views

A block must start with a tag name

I have that simple variable in my javascript var toLoad = '{% "include _views/reviews.twig" %}'; and on a page load I get template error that is defined in the title of question. That variable is ...
1
vote
2answers
76 views

Managing shared content in Craft

I'm fairly new to Craft. I have a question about how to manage and setup the editing of shared content in Craft which is used on multiple pages. As an example I have a Mailing List signup element ...
2
votes
1answer
707 views

Including and reusing common code per matrix block

In each matrix block, I'm allowing users to set a background image, background color etc with a settings field. In each matrix block template, I have: {% block content %} {% set backgroundColor = ...
1
vote
1answer
134 views

How to pass Calendar ID to include

I am using Michael Rog's Calendar plug-in and am trying to pass the calendar ID to an include. Parent template: {% include '_includes/_calendar' with {'calendarId': '1'} %} _includes/_calendar: {% ...
2
votes
1answer
1k views

Can you pass a variable with includeJsFile?

Can you do something similar to using "with" in twig's include tag (http://twig.sensiolabs.org/doc/tags/include.html), but instead with includeJsFile? I am using a plugin to filter my entries by ...
0
votes
1answer
5k views

Passing variable from block within including template

I have this situation, where variable param doesn't exist. skeleton.twig {# Inject template #} {% block var %}{% endblock %} {% include '_includes/template' %} Now I want to extends index.twig ...
0
votes
1answer
1k views

For performance is using a macro better than using include with the 'with' statement?

Which is better for performance? Using a macro for output in a for loop or calling an include using the 'with' params to pass data? Both are loading a file. But is stacking up a bunch of code in a ...
1
vote
1answer
1k views

Using a variable with Twig include

I am trying to use a variable, based on an entry field, to load a form with a Twig include. The code is pretty straightforward: {% set theForm = entry.formSelect %} {% include theForm %} Doing this ...
2
votes
2answers
304 views

Multiple Service/Variable/Controller plugin files

I'm not sure if I missed documentation on it, but is there a method to follow when including additional plugin files for services, controllers, variables etc.? For bigger plugins it'd help to do ...
3
votes
1answer
3k views

How to dynamically set an include template

I have a series of structure items, each with a product id, based on this id I would like to load in an additional template. Something like this: {% set embedAsset = entry.productId %} {% include "...
4
votes
4answers
450 views

How to move repeating code into an include template

I'm new to Craft and have created some SEO fields similar to this, and the template code appears in all templates as shown below. I don't want to be repeating all that code in every template though, ...
8
votes
5answers
26k views

Include a template that sets variables (global template variables)

I'm essentially looking for a way to have a template that runs through a bunch of sets that I might use throughout my templates. The problem is, if I include in a template with an extends, it dies up ...
1
vote
1answer
4k views

Correct way to include include scripts

I am including head.html and scripts.html in my template. Most of the scripts load except for 2 yet the path is the same for all of them. I {% include %} them. If I change foundation.min.js to ...
4
votes
1answer
4k views

How would I pass and entry's field value to an include?

I have this: {% include "partials/includes/page-header" with { 'title' : '{{ entry.heading }}' } %} But it seems that nothing I do will actually pass {{ entry.heading }} as 'title' in the include.