We are creating a template that our client would use on many pages of their website, for example 'Accordion Layout Template'.

So we create a page 'Bikes', assign the 'Accordion Layout Template', then create and select the channel named 'Bikes'

Is there a way to get the selected channel for the page, so we do not have to hard code the channel into the template like below:

{exp:channel:entries channel="bikes"

but ideally it would be

{exp:channel:entries channel="Get_Selected_Channel"

Thank you.

1 Answer 1


If you are planning to develop a 'generic' block of template code and then reuse it multiple times within your site, you necessarily need a mechanism for specifying what data you want to display through the template.

As you point out, a common way to provide this data to a template is via the channel:entries tag pair. If I understand your question correctly, you are looking for a way to specify the channel to use in such a call using a variable rather than hard-coding a specific channel.

There would appear to be at least four different ways you could go about this.

One option is to use one of the URL segments to identify the channel to use - so for example something like this:

{exp:channel:entries channel='{segment_2}' dynamic='no' ... etc. }

A second option is to use a layout variable set in (one of) the template(s) linking through to the block of reusable code - so for example something like this:

{exp:channel:entries channel='{layout:channel_name}' dynamic ='no' ... etc.}

A third option would be to use an embed variable set in the call to the embeded template - something like this:

{exp:channel:entries channel='{embed:channel_name}' dynamic ='no' ... etc.}

A fourth option would be to store the channel information in a stash variable elsewhere and retrieve it when required - something like this:

{exp:channel:entries channel="{exp:stash:get name='channel_name'}" dynamic ="no" ... etc.}

What you choose will be determined by how your site is designed and what you are hoping to achieve through re-using the code block.


  • Very good explanation!
    – Stéphane
    Commented Apr 25, 2018 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.