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.

When can a variable be passed in a argument to a plugin tag? When can't it?

August 15, 2012 4:22pm

Subscribe [2]
  • #1 / Aug 15, 2012 4:22pm

    FTIC

    14 posts

    It seems sometimes a variable within a tag argument will be parsed and other times it won’t be. I can’t figure out what determines it.

    I’m using Image Sizer to resize images. The path to the image is stored in a variable. At one point in my template, passing a variable works. At another point in the same template, it doesn’t work. The variable I’m passing is called “main_image” and comes from the current entry within the loop. For example:

    Use case 1 (works)

    {exp:channel:entries .... }
       main image: {main_image} </br>
       <!-- passing {main_image} works -->
       {exp:imgsizer:size src="{main_image}" width="150"}
           {sized}
       {/exp:imgsizer:size}
    {/exp:channel:entries}

    Use case 2 (doesn’t work)

    {exp:myPlugin:getEntries .... }
       main image: {main_image} </br>
       <!-- passing {main_image} does not work -->
       {exp:imgsizer:size src="{main_image}" width="150"}
           {sized}
       {/exp:imgsizer:size}
    {/exp:myPlugin:getEntries}

    - In the second use case, “inner” markup is rendered by myPlugin via EE->TMPL->parse_variables.
    - In the second use case, Image Sizer receives the image src as “{main_image}” i.e. the unparsed variable name.
    - I can successfully print main_image value outside of the imgsizer tag in both cases.

  • #2 / Aug 15, 2012 6:09pm

    johndwells

    94 posts

    Hi FTIC,

    I think you’re dealing with a parse order. It’s briefly discussed in the docs:

    http://ellislab.com/expressionengine/user-guide/templates/plugins.html#changing-parsing-order

    And of course the bible PDF of parse order from @low:

    http://loweblog.com/downloads/ee-parse-order.pdf

    So try adding parse=“inward” as a parameter to your outer plugin tag, and it should work:

    {exp:myPlugin:getEntries .... parse="inward"}

    HTH,
    John

  • #3 / Aug 15, 2012 6:15pm

    johndwells

    94 posts

    p.s. Module tags, like the {exp:channel:entries} one you gave as example 1, are always parsed “inward” - hence why it works as expected.  Plugins by default are parsed “outward”, but can be reversed.  And no, parse=“outward” has no effect on module tags. 😊

  • #4 / Aug 16, 2012 11:16am

    FTIC

    14 posts

    [removed]

  • #5 / Aug 16, 2012 11:34am

    FTIC

    14 posts

    I thought parse=“inward” might have been the issue but it wasn’t fixing the problem. Turns out it does get me one step further, but I still have an issue with a variable in my argument.

    {main_image} is now getting interpreted but main_image also includes a variable, like:

    https://ellislab.com/asset/images/team-photo/my_image.jpg

    Now, filedir_1 is not getting parsed.

  • #6 / Aug 16, 2012 11:44am

    johndwells

    94 posts

    Hi FTIC,

    I believe that’s because the {filedir_X} are “early” global variables, meaning they’re being parsed before your plugin is being run.  So your plugin will actually need to parse that manually.  Something like this:

    $this->EE->load->library('typography');
    $this->EE->typography->parse_images = TRUE;
    $field_data = $this->EE->typography->parse_file_paths($field_data);

    - borrowed from https://github.com/iainurquhart/Garfield

    Cheers,
    John

  • #7 / Aug 16, 2012 11:49am

    FTIC

    14 posts

    Ah. Well, it isn’t my plugin. I could fix it but if not, I found a way around it using Stash:

    {exp:stash:set name="main_image" parse_tags="yes"}{main_image}{/exp:stash:set}
    {exp:imgsizer:size src="{exp:stash:get name='main_image'}" width="150" height="150" parse="inward"} 
         {sized}
    {/exp:imgsizer:size}
  • #8 / Aug 16, 2012 11:52am

    johndwells

    94 posts

    Nice. Which plugin was it?  They might want to be notified so it can be fixed in a later release.

    Cheers,
    John

  • #9 / Aug 16, 2012 12:00pm

    FTIC

    14 posts

    ImageSizer by David Rencher

  • #10 / Aug 16, 2012 12:30pm

    johndwells

    94 posts

    Hi FTIC,

    Did you try putting parse=“inward” on your outer plugin tag?  Like so:

    {exp:myPlugin:getEntries .... parse="inward"}
       main image: {main_image} </br>
    
       {exp:imgsizer:size src="{main_image}" width="150"}
           {sized}
       {/exp:imgsizer:size}
    {/exp:myPlugin:getEntries}

    Technically, if I’m reading your setup correctly, the inward parse needs to be set to your outer plugin, not the inner one.  The fact that placing parse=“inward” on the inner imgsizer plugin tags is sort of a coincidence in that parse=“inward” tells EE to parse the tag pair parameters before processing itself.  I realise this is all a bit convoluted…

    The Garfield plugin I referenced to in an earlier post is worth a closer look at it’s documentation and source code. The code is clean and simple, and demonstrates how to parse varaibles, conditionals, respect the no_results conditional and more - and the readme docs state that for it to work, parse=“inward” must be used.

    Cheers!
    John

  • #11 / Aug 16, 2012 12:37pm

    FTIC

    14 posts

    Yes, I ended up with it on the outer tag. I had just put it on both for good measure but everything is working with it on the outer tag and a tiny fix in Image Sizer to parse file paths. Thanks for your help!

  • #12 / Aug 17, 2012 10:34am

    Shane Eckert

    7174 posts

    Hey FTIC,

    I am glad to see that johndwells was able to help you out! That’s awesome.

    If you need anything else, please just let me know by opening a new thread.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases