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.

Pass php var into exp:channel:entries tag

April 16, 2011 4:43pm

Subscribe [3]
  • #1 / Apr 16, 2011 4:43pm

    ibuck

    19 posts

    I am trying to pass a php variable into the exp:channel:entries tag year attribute and not having much luck. Here is what I currently have:

    <?php 
      $year = 2010; // hardcoded for example
    ?>
    {exp:channel:entries channel="news_items" dynamic="no" year="<?php echo $year ?>"}
    
    {/exp:channel:entries}

    Is this possible or is there a way to debug what is actually getting into the “year” attribute? It only works when the year is 2011 but anything older (2010, 2009) just returns all entries from 2011.


    Using ee 2.1.3 (20110411)

  • #2 / Apr 16, 2011 4:57pm

    Mark Bowen

    12637 posts

    Hiya,

    Ensure that you have PHP parsing stage set to Input and not Output. I believe that may be what’s happening here.

    Also I don’t think it’s massively important but you are missing a semi-colon at the end of the echo statement. I believe it’s not needed if you have a one liner of PHP but I think it’s always good to put them in anyway so that you don’t miss them on longer pieces of code.

    <?php 
      $year = "2010"; // hardcoded for example
    ?>
    {exp:channel:entries channel="news_items" dynamic="no" year="<?php echo $year; ?>"}
    
    {/exp:channel:entries}

    Hope that helps a bit.

    Best wishes,

    Mark

  • #3 / Apr 16, 2011 5:02pm

    ibuck

    19 posts

    That fixed it (Output to Input). Thanks so much for the quick reply. Thought I was going crazy there for a sec.

  • #4 / Apr 16, 2011 5:04pm

    Mark Bowen

    12637 posts

    That fixed it (Output to Input). Thanks so much for the quick reply. Thought I was going crazy there for a sec.

    No problem at all. Glad that got it sorted for you.

    Best wishes,

    Mark

  • #5 / Apr 18, 2011 4:06am

    John Henry Donovan

    12339 posts

    Thanks Mark. Feel free ibuck to start a new thread if you have any more questions

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

ExpressionEngine News!

#eecms, #events, #releases