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.

Passing a variable to an xml template

August 22, 2008 7:33am

Subscribe [2]
  • #1 / Aug 22, 2008 7:33am

    Carlo Poso

    35 posts

    Hi all,
    I need to pass a variable from within a Web Page Template to an xml Template

    I have a sql query inside this xml which I’m trying to customize depending on the value of the variable I want to pass on to it.

    Any idea?!

    Carlo

  • #2 / Aug 22, 2008 7:45am

    Mark Bowen

    12637 posts

    Hi Carlo,

    The easiest way would be using segment variables wouldn’t it? Other ways would be either session variables or a cookie perhaps?

    You should be able to pass data on from one template to another quite easily using any of these methods so if these are no good then perhaps you could show some code so that we know exactly what you are trying to accomplish and then we can have some more thoughts on it for you.

    Hope that helps though.

    Best wishes,

    Mark

  • #3 / Aug 22, 2008 8:13am

    Carlo Poso

    35 posts

    Hi Mark,
    I’ve this template from which I want to get the {segment_3}, right.
    So, it’s something like http://www.mysite.it/index.php/templategroup_A/template_A/entry-title

    I’d like to make available the entry-title inside my destination xml Template, which is in another Template Group, like:

    http://www.mysite.it/index.php/templategroup_B/templatexml

    Don’t know how to do it with segment variables (uhmmm..don’t think it’d work…).

    I’m trying with the session variables pluging from PutYourLightsOn but still no luck.

    Here’s part of the code from template_A:

    {exp:weblog:entries weblog="{exp:translator:simple weblog="cgp_libri"}" disable="pagination"}
    ...
    ...
    {exp:session_variables:set name="segment" value="{segment_3}"}

    ...and here’s part of the code from my xml file…

    {exp:weblog:entries weblog="{exp:translator:simple weblog="cgp_libri"}" url_title="{exp:session_variables:set name="segment" value="POSTED_VARIABLE"}" disable="pagination"}
    ...
    ...

    It’s not clear to me whether to use

    {exp:session_variables:set name="segment" value="POSTED_VARIABLE"}
    or
    {exp:session_variables:get name="segment"}

    inside the xml. Both seem not to work.

    Help!

  • #4 / Aug 22, 2008 8:51am

    Mark Bowen

    12637 posts

    Hi Carlo,

    Hmm a little confuddled from what you have posted but here goes.

    What you need to do is have the segment variable tacked on to the end of the second link that you showed, something like this :

    http://www.mysite.it/index.php/templategroup_B/templatexml/entry-title

    You can then use the {segment_3} variable directly from within that template. If however the segment is on another template then you will need to send this data across to the second (xml) template in order for this to work.

    If you try the following URL (replace bits where needed with your own information though first 😉 ) and see if it gets you what you need.

    http://www.mysite.it/index.php/templategroup_B/templatexml/entry-title


    Then have this in your XML template :

    {exp:weblog:entries weblog="{exp:translator:simple weblog="cgp_libri"}" url_title="{segment_3}" disable="pagination"}
    …
    …
    {/exp:weblog:entries}

    That should hopefully get you what you need.

    Hope that helps.

    Best wishes,

    Mark

  • #5 / Aug 22, 2008 9:41am

    Carlo Poso

    35 posts

    Hi Mark,
    for sure this would work, but let me explain better the situation, if I manage to 😊

    My template A shows a given weblog entry:

    http://www.mysite.it/index.php/templategroup_A/template_A/entry-title

    The same template triggers a javascript which calls the xml (http://www.mysite.it/index.php/templategroup_B/templatexml) to get related photos from the Gallery and put them inside Monoslideshow, always in the same page.
    Since each weblog post has its own related photos (through the Solspace Tag Module), I need to pass to the xml the {segment_3} value, so that the xml can get the right images.

    I’ve fully understood what you’ve written and yes, that could be a solution but how do I hook the {segment_3} of the URL http://www.mysite.it/index.php/templategroup_A/template_A/entry-title to http://www.mysite.it/index.php/templategroup_B/templatexml?

    Carlo

  • #6 / Aug 22, 2008 9:56am

    Mark Bowen

    12637 posts

    Okay now I admit it I’m a little lost, sorry.

    So you are using the Gallery Module, yes? When you say the page is pulling related photos from the Gallery then how exactly have they been related?

    Also do you have a link to the site in question perhaps? Sometimes it’s easier for me to understand what is needed when I see things in the flesh 😉

    One last thing - I don’t know if you are definitely reliant upon using the Gallery Module but was just wondering if you had thought about using a weblog to hold your gallery images instead. Myself personally I always do this as it offers me so much more power and flexibility and I reckon that whatever it is that you are trying to do would probably be a lot easier if you did do this?

    Best wishes,

    Mark

  • #7 / Aug 22, 2008 10:16am

    Carlo Poso

    35 posts

    Hey Mark, can’t believe I did it!

    Look here at monolideshow: http://www.claragigipadovani.it/index.php/sito/libro-dettaglio/passione-nutella/

    And the other gallery here: http://www.claragigipadovani.it/index.php/sito/libro-dettaglio/giandujotto-mania/


    I’m using the Gallery Module this way.

    I have one main Category and some sub categories in my photogallery. Admins can upload pics into a chosen category, plus they can choose Tags so that I can also make relationships with weblog entries on-the-fly, by tagging them as well.

    The pages I’ve just given you the links to, pull out a weblog entry which has been related to one of these subcategories via the brilliant ext.gallery_cats (http://ellislab.com/forums/viewthread/37200/P0/).
    This allows me to get all the pics inside a given category and show them in the page beside my weblog entry.

    Since each photo has been tagged, I managed to get monoslideshow to divide related photos into groups (albums), each group being a tag. You can see it clearly on the pages above.

    Does it make sense? It’s a bit complicated but it works…
    Carlo

  • #8 / Aug 22, 2008 10:22am

    Mark Bowen

    12637 posts

    Hey Mark, can’t believe I did it!

    Look here at monolideshow: http://www.claragigipadovani.it/index.php/sito/libro-dettaglio/passione-nutella/

    And the other gallery here: http://www.claragigipadovani.it/index.php/sito/libro-dettaglio/giandujotto-mania/

    Hi Carlo,

    Unfortunately I can’t see anything at those links as they just show a syntax error about the usage of the session variables plugin but I’m glad you have it working now.

    I still think from what you have shown in your last post that this would all be a lot easier using a weblog to hold the images. You would still have your categories and sub-categories and the full use of the Tag module and you could pull out images from the weblogs a lot easier but that’s just the way I would do it.

    Glad it’s working for you though.

    Best wishes,

    Mark

  • #9 / Aug 22, 2008 10:24am

    Carlo Poso

    35 posts

    Yep sorry, have a look now…

  • #10 / Aug 22, 2008 10:25am

    Carlo Poso

    35 posts

    I see Mark, but what about the resizing features of the Gallery Module? Would have been possibile to use them inside a weblog?

  • #11 / Aug 22, 2008 10:58am

    Mark Bowen

    12637 posts

    Ah yes that’s better all working now.

    If you want to be able to resize images then I personally always use the fantastic Image Sizer plugin which allows you to upload the largest size image you are going to need to use anywhere on your site (don’t make it too big of course 😉 ) and then you can simply make the plugin resize the image on the fly for you at whatever size you need for whatever template.

    All the images are cached so once they have been made once there is no overhead to speak of and at any point if you say changed the look of your template and you wanted to change the sizes of all the images in your entries then this can happen automatically. You would simply update the size parameters in the plugin tag and it will re-create new images at the size(s) you now want.

    A lot lot easier in my eyes but that’s just the way I do it.

    Don’t know if that helps at all.

    Best wishes,

    Mark

  • #12 / Aug 22, 2008 11:04am

    Carlo Poso

    35 posts

    Good to know Mark, didn’t know such a tool for EE existed.
    Might be able to follow these steps in my next project.
    Carlo

  • #13 / Aug 22, 2008 11:10am

    Mark Bowen

    12637 posts

    Good to know Mark, didn’t know such a tool for EE existed.
    Might be able to follow these steps in my next project.
    Carlo

    No problem. You know where I am if you ever need a hand with it 😉

    Best wishes,

    Mark

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

ExpressionEngine News!

#eecms, #events, #releases