Take the 2-minute tour ×
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It's 100% free, no registration required.

I was wondering.. can I use the same template to display the page in two different layouts?

and how you can switch from one layout to another without adding any segment?

it would be nice for me to use a simple query url, so that you have:

http://mysite.it/portfolio?=list

or

http://mysite.it/portfolio?=thumb

How can I adopt this solution? Thank you!


EDIT: This is a solution found (thanks to Andrew Fairlie and Jean St-Amand):

{exp:switchee variable="{get:view}" parse="inward"}
    {case value="grid" default="yes"}
        {switchee variable="{get:tag}" parse="inward"}
            {case value="{get:tag}"}
                <div data-role="infinite-scroll" class="block-stack">
                {embed="portfolio/embed-tags"} 
                </div>
            {/case}
            {case default="yes"}
                <div data-role="infinite-scroll" class="block-stack">
                {embed="portfolio/embed-ajax" infinite_scroll_vars="category_id|category_name|segment_1|segment_2" infinite_scroll_values="{segment_2_category_id}|{segment_2_category_name}|{segment_1}|{segment_2}"} 
                </div>
            {/case}
        {/switchee}
    {/case}
    {case value="list"}
        <div data-role="infinite-scroll" class="block-stack">
        {embed="portfolio/embed-ajax-list" infinite_scroll_vars="category_id|category_name|segment_1|segment_2" infinite_scroll_values="{segment_2_category_id}|{segment_2_category_name}|{segment_1}|{segment_2}"} 
        </div>
    {/case}
{/exp:switchee}
share|improve this question

2 Answers 2

up vote 2 down vote accepted

I'm assuming you're referring to EE 2.8 layouts.

It isn't possible to process layouts within a plugin or module tags so using an if statement or Switchee isn't going to work within the template itself.

However you could use something like Switchee as Jean St-Amand mentioned within the layout to provide variations of that layout depending on the string.

You could use the Mo'Variables {get:parameter} tag to get it.

So your layout template may look a bit like...

{exp:switchee case="{get:view}"}
    {case value="list" default="yes"}
            {!-- Do whatever you need to do here --}
    {/case}
    {case value="thumb"}
            {!-- Do whatever you need to do here --}
    {/case}
{/exp:switchee}

However you might find it better to look into EE 2.8's new template routes which allows you to serve up different templates and layouts based on the URL.

If you're worried about duplicate content with these 2 URLs you could set the canonical tag to be your preferred 'default' view.

Alternatively, this may be a job better suited to Stash lists.

Useful pages

share|improve this answer
    
thank you Andrew, it works like a sharm! –  Valerio Mar 5 at 16:08
    
Excellent. Which option did you go for in the end? –  Andrew Fairlie Mar 5 at 16:13
    
I've just edited my 1th question with the solution ;) –  Valerio Mar 5 at 16:15

Seems like you ought to be able to handle it with switchee using regex to determine which layout scenario is present in your URL, for example. I'm not a regex wiz so I won't pretend to know what patterns you would need - but it's switch case logic coupled with its support for regex is what made me think of it as a possible answer for you.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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