ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Dynamic Template Variables

January 10, 2011 3:13pm

Subscribe [4]
  • #1 / Jan 10, 2011 3:13pm

    Dan G

    7 posts

    Is there a way of assigning dynamic variables in a template, and reusing them within the exp tag?

    I want to display a main article and a list of further article titles. I don’t want the main article title to appear in the list of further titles. So what I wanted was to be able to output the main article, set a variable for the entry id, then use the

    entry_id="not {var_entry_id}"

    entries tag parameter.

    If this is not possible, Is there a better approach to what I’m trying to acheive?

    Thanks,
    Dan

    Moved to CodeShare Corner by Moderator

  • #2 / Jan 11, 2011 2:54am

    John Henry Donovan

    12339 posts

    Dan ,

    Would something like this work for you?

    This would be your article page

    {exp:channel:entries channel="news" status="not closed" limit="1"}
    <h1>{title}</h1
    {body}
    <hr>
    <h2>More Articles</h2>
    <p>{embed="news/more_articles" not_this_one="{entry_id}"}<br />
    {/exp:channel:entries}

    The in your embed called ‘more_articles’

    {exp:channel:entries channel="news" status="not closed" limit="10" dynamic="no" entry_id="not {embed:not_this_one}"}
    <ul>
    <li>{title}</li>
    </ul>
    
    {/exp:channel:entries}
  • #3 / Jan 11, 2011 6:37am

    Dan G

    7 posts

    Thanks for your reply John.

    That would solve the problem i described. What would I do though if there were a few featured articles at the top, then the rest were displayed below? I wouldn’t be able to use the method you described.

    Thanks,
    Dan

  • #4 / Jan 11, 2011 5:05pm

    Ingmar

    29245 posts

    You’d probably need to use PHP for that purpose, or hard-code your exclusion list, as it were.

  • #5 / Jan 11, 2011 6:04pm

    Dan G

    7 posts

    Thanks, would you be able to point me towards help in using PHP in this way with Expression Engine. I’ve used CodeIgniter but this is my first time with EE.

    Thanks,
    Dan

  • #6 / Jan 12, 2011 8:20am

    Sue Crocker

    26054 posts

    I’d be more likely to use the query module to build a query excluding the entry ides. But that’s more of a HowTo or CodeShare Corner kind of question.. moving there for additional community support.

  • #7 / Jan 12, 2011 3:22pm

    Dan G

    7 posts

    Thanks Sue for the pointer. Can anyone give me any advice on how to build a query module to do this?

    Thanks,
    Dan

  • #8 / Jan 20, 2011 10:45am

    Dan G

    7 posts

    I’d just like to post the solution I used in case anyone else can benefit.

    I have 4 “featured” stories at the top, and 10 further stories afterwards.

    I want to order the featured articles by “featured_date”, and the further articles by entry date.

    I don’t want to have the same items repeating in the further articles as were in in the featured ones.

    To solve the problem I made a separate template “morearticles”, and I feed it the variables it needs through the main template. I also need to generate the same entry ids as the 4 featured items with mysql in order to tell the morearticle template what not to display.

    Main template code:

    <ol>
    {exp:channel:entries channel="news" orderby="news_featured_date|date" sort="desc|desc" limit="3" offset="1"}
        <li>
            <h3>{title}</h3>
    <p>        {news_summary}<br />
            <a href="/news/{categories">Read More…</a><br />
        </li><br />
    {/exp:channel:entries}<br />
    </ol></p>
    
    <p>        {embed="site/morearticles"<br />
                channel="news"<br />
                entry_id="not {exp:query sql="<br />
                    SELECT t1.entry_id<br />
                    FROM exp_channel_data AS t1, exp_category_posts AS t2, exp_channel_titles AS t3<br />
                    WHERE t1.channel_id =  '2'<br />
                    AND t1.entry_id = t2.entry_id<br />
                    AND t1.entry_id = t3.entry_id<br />
                    ORDER BY t1.field_id_59 DESC, t3.entry_date DESC<br />
                    LIMIT 4<br />
                " backspace="1"}{entry_id}|{/exp:query}"<br />
                orderby="date"<br />
                sort="desc"<br />
                limit="10"<br />
                href="/news"<br />
                archivelink="/news/all/archive"<br />
                archivelabel="News Archive"<br />
            }

    “morearticles” Embed code:

    <ol id="morearticles">
        {exp:channel:entries channel="{embed:channel}" category="{embed:category}" entry_id="{embed:entry_id}" orderby="{embed:orderby}" sort="{embed:sort}" limit="{embed:limit}"}
        <li><a href="http://{embed:href}/{categories">{title}</a></li>
        {/exp:channel:entries}
        <li class="archivelink"><a href="http://{embed:archivelink}">{embed:archivelabel}</a></li>
    </ol>

    Hope this can help.

    Cheers,
    Dan

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases