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.

How do I create variables in EE2

March 01, 2013 9:33am

Subscribe [2]
  • #1 / Mar 01, 2013 9:33am

    iPixel

    64 posts

    EE 1.X used to have

    {assign_variable:variable_name="{entry_id}"

    That seems to have been removed in EE2, and all I can find is

    {preload_replace:variable_name="replacement"}

    However, that does not do what i need it for.

    Inside my {exp:channel:entries} tag, i need to capture the {entry_id} for use outside of the {exp:channel:entries} tag. How can I accomplish this?

    Doing this

    {preload_replace:SavedEntryID="{entry_id}"}

    literally assigns the text {entry_id} to the variables value. Instead of {entry_id}‘s value.

  • #2 / Mar 01, 2013 2:12pm

    Rob Allen

    3105 posts

    Not sure but one of these plugins may help to capture the current ID

    http://devot-ee.com/add-ons/entry-data
    http://devot-ee.com/add-ons/url-title-to-entry-id

  • #3 / Mar 01, 2013 2:37pm

    iPixel

    64 posts

    Thanks, however I want to avoid using any plugins. I’ll sooner switch to using php instead of EE syntax if there’s no other way.

  • #4 / Mar 01, 2013 2:52pm

    Rob Allen

    3105 posts

    In that case an embedded template may work:

    Add a channel entry tag to get the ID (or you could use the existing tag)

    {exp:channel:entries channel="my_channel" limit="1"}
    {embed="inc/my-embed-template" the _id="{entry_id}"}
    {/exp:channel:entries}

    Then in your embed template you can pull in the ID

    The id is {embed:the_id}
  • #5 / Mar 01, 2013 3:27pm

    iPixel

    64 posts

    Good solution, but it just makes me wonder more and more why {assign_variable} was removed. Just look at all the hoops we need to jump through just do pass a simple value outside of the {exp:channel} tag.

  • #6 / Mar 01, 2013 4:18pm

    iPixel

    64 posts

    The solution I ended up going with, at least until i see a way to do it via ee-syntax is..

    placing a bit of php within the {exp:channel} tag.

    <?php $entryID = "{entry_id}"; ?>

    and now i can use $entryID outside of the {exp:channel} tag.

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

ExpressionEngine News!

#eecms, #events, #releases