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.

Why does Var_Dump return More Characters then Visible in {channel_short_name} ?

April 23, 2011 2:13pm

Subscribe [6]
  • #1 / Apr 23, 2011 2:13pm

    Jan Paul

    74 posts

    Hi, first here is the code…

    $channel = '{exp:channel:entries url_title="{segment_1}"}{channel_short_name}{/exp:channel:entries}';
    var_dump($channel);

    Now here’s my problem…

    Var_dump is returning string(97) “hardlopen-sporten” (hardlopen-sporten is the short channel name). But hardlopen-sporten is only 17 characters long… So why is var_dump telling me that the string is 97 characters long?

    I want to use the $channel variable to do this “{exp:channel:entries channel="<?php echo $channel; ?>"}”. But the problem is, that isn’t working because the $channel string doesn’t match the channel name. It does match visually when I echo it out, but when I do a var_dump, it says the string is way longer.

    Can someone explain to me what is going on and how I can make this work?

  • #2 / Apr 23, 2011 2:48pm

    giusi

    94 posts

    Hi.

    Are you sure you need to do {exp:channel:entries channel=”<?php echo $channel; ?>”} ? Depending on the stuation there are many ways to dinamically set the channel parameter. Could you explain in more detail what you are trying to accomplish?

  • #3 / Apr 23, 2011 3:01pm

    Jan Paul

    74 posts

    I think I need it yes, I’m not 100% sure there’s no other way… But the channel isn’t in the URL for single entries, so I can’t dynamically get it from there. I have this URL structure: domain.com/entry-title.

    What I’m trying to accomplish is a listing of articles sorted by # of views (in a sidebar next to my articles). The articles listed should only be from the channel that the article belongs to.

    Here’s such an article: http://www.nuafvallen.nl/zichtbare-buikspieren. The listings will be displayed in the “Populaire Onderwerpen” sidebar.

  • #4 / Apr 23, 2011 3:11pm

    giusi

    94 posts

    This plugin together with the {channel_short_name} variable should solve your issue. If you need more details feel free to ask.

  • #5 / Apr 23, 2011 3:59pm

    narration

    773 posts

    Jan Paul, is it 97, or maybe 87 actually, in characters?

    What is happening here is about parse order, as the entries tag is processed after PHP-on-input. Thus the long length is the length of your pre-parsed string for setting $channel, which I count as on or about 87.

    Here’s a chart on parse order, prepared in fine detail by one of your fellow Dutchmen, who’s known around here as Low. You can use it for your issue by noting that exp:entries is a module tag, from the channel module, so it’s evaluated around the middle of parse order.

    Low has also built a very useful add-on called Low Variables, but I think that is not what you need here, as really, it is about Constants.

    Here may be a possible form of solution, though: the String add-on, from Ty Wangsness, at eMarketSouth.

    —You would use this add-on’s ‘set’ tag to form your needed value, and to hold it for use rather than making a PHP variable.

    —quite possibly, you can use the ‘set’ tag in your template within your normal use of the exp:entries block.

    —You would place your access to the variable in an EE embed, using the ‘output’ tag.

    —You would call the embed at any position you want the result to show, in the top template: even _before_ the value has apparently been set within an exp:entries block.

    This works because in the parsing order, an embed is run only after everything in its higher template has been completed—except that its evaluation is inserted into the overall results.

    It’s a clever solution, and not expensive.

    Hoping this helps your case, and for others who run into this kind of need.

    If EE isn’t exactly a conventional programming language, its fit with one is interesting. Here in the solution you’re getting to use a value before it’s been computed—a kind of lazy evaluation, as it’s called.

    Regards,
    Clive

  • #6 / Apr 23, 2011 4:34pm

    narration

    773 posts

    p.s. I hadn’t wanted to get into actual discussion of what you saw falsely in text from var_dump, but after walking away from this, probably a glimpse came of the answer.

    - you are using var_dump as it needs to be, within the PHP evaluation area.

    - however, as we’ve found, parse order means the $channel PHP variable would at that moment hold the unevaluated EE code.

    - var_dump correctly reports its length.

    - var_dump also correctly reports the content, the long string of unevaluated EE tags, but you don’t see that.

    - you don’t see it because later in the parse order, EE properly evaluates that string just as var_dump printed it, and replaces the results there with the actual value, which is the short channel name you originally wanted.

  • #7 / Apr 23, 2011 4:40pm

    giusi

    94 posts

    Hi narration,

    since you seem to have a deep understading of the reason that determines the issue, I am curious to know what you think of the solution I proposed (the mx jumper add-on). I have thought it to be a more clean and agile solution, maybe it has some drawback i can’t see?

  • #8 / Apr 23, 2011 5:01pm

    narration

    773 posts

    Hi giusi—

    Well, this is the thing with forums. Greatly useful for their knowledge and contexts pools, but as yet they don’t operate in real time. So I was writing while you were also, and not knowing about it.

    Maybe it’s a thought for what a really stellar new EE forum design could include, as well as the more obvious.

    Now, here’s an answer anyway for your thoughts.

    - I like Max’s work a lot, and I actually thought of this type of solution first. But when I googled to find such a plugin, knowing there had been several, Ty’s solution turned up prominently on my search, and I remembered it.

    - Is there a difference in elegance or subtle factors? I think in fact that there is, and it probably comes down on the side of Ty’s String plugin solution, even though it takes very slightly more to use.

    - The problem with earlier string ‘movement’ plugins, at least as I remember so, is that they tended to become unreliable over time, as EE releases advanced. That would be natural, at least, because they’re involving themselves with EE internals operation. And then your customer could turn up, perhaps subtly so you don’t notice it on doing an update or upgrade, with a site that no longer works correctly.

    - On the other hand, with Ty’s approach, you are simply using a new set of tags, creatable and usable mostly without depending on much of detail, or that is likely to change, in EE internal function. So my sense would be that it is a more reliable approach.


    Good questions to raise, giusi, the ones in front and the ones in back.

    Regards,
    Clive

  • #9 / Apr 23, 2011 5:06pm

    giusi

    94 posts

    Thanks for the clarification, very instructive : )

  • #10 / Apr 23, 2011 5:07pm

    Jan Paul

    74 posts

    Thank you both for the helpful suggestions, and the explanation narration. With all this ammunition I should be able to tackle this problem tomorrow.

  • #11 / Apr 23, 2011 5:10pm

    narration

    773 posts

    and as a p.s. for you also, giusi, afterwards I remembered one more thing.

    - actually, at least one of those ‘string move’ plugins worked a lot like Ty’s does, internally. A dim memory of its code, but had looked at it.

    - if so, then I really don’t know why it became unreliable. Maybe just a factor of implementation.

    - however, turning again, it’s often a practice in EE to use an embed to decouple interfering activities, like nested tags. So the fact that Ty uses the embed as the mechanism to allow completely free movement is again likely to be more reliable, by avoiding potential conflicts.

    - I kind of felt that the embed method was also likely to remain reliable because embed processing would be highly unlikely to move from its present post-template event position.


    Ok, and I am stopping before thinking of more, as is tending to happen 😉.

    A nice week-end to you, giusi, and each involved here.

    Clive

  • #12 / Apr 23, 2011 5:13pm

    narration

    773 posts

    Jan Paul, very good, and it will be good to hear how this works out for you.

    Regards,
    Clive

  • #13 / Apr 24, 2011 6:55am

    Jan Paul

    74 posts

    Hi, I’ve tried both plugins but they don’t work.

    I have this in my single-entry template: {exp:string:set name="foo"}{channel_short_name}{/exp:string:set}.

    And then this in the sidebar(include):

    {exp:string:output}
      {exp:channel:entries channel="{foo}" dynamic="off" limit="10" orderby="view_count_one"}
        <li><a href="http://{path={url_title}}">{title}</a></li>
      {/exp:channel:entries}
    {/exp:string:output}

    {foo} does show the {channel_short_name} string when I use it in the content area, but when I put it inside the channel:entries tag the tag doesn’t load the channel that {foo} contains.

    Edit: Tried to put the {channel_short_name} in a snippet because: “Snippets are expanded at a very early stage on each template, making it possible for them to hold dynamic content”, but that didn’t work also.

  • #14 / Apr 24, 2011 10:49am

    giusi

    94 posts

    EDIT: this won’t work in this form. The variable isn’t evaluated as a parameter of the channel:entries tag.  I am trying to understand how make it work.

    Hi.

    I never used the String plug-in so I can’t help with it.

    With the MX Jumper you coukd try something like this

    {exp:channel:entries channel="channel_name"}
    {exp:mx_jumper:put name="variable_name"}channel_short_name{/exp:mx_jumper:put} 
    {/exp:channel:entries}

    Then in your embed

    {exp:channel:entries channel="{exp:mx_jumper:out name=“variable_name”}"}
    code…
    {exp:channel:entries}
  • #15 / Apr 24, 2011 11:01am

    Jan Paul

    74 posts

    Yeah, I’ve tried that but it doesn’t work. The problem with everything I’ve tried so far is the parse order I think.

    E.g. when I use MX jumper’s output tag: {exp:mx_jumper:out name='foo'}, it works fine when I display it as content, but inside the exp:channel:entries it just doesn’t work, no matter which version of the tag I use.

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

ExpressionEngine News!

#eecms, #events, #releases