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.

Embedding EE Tags in Publish/Edit entry fields...

January 22, 2008 6:28pm

Subscribe [5]
  • #1 / Jan 22, 2008 6:28pm

    GhostMeat

    2 posts

    This seems like it would be a common question, but I can’t seem to find any banter about it. 

    I’m building a site for a non-prof, using EE strictly as a CMS and I am just using the EE Core system for now.  In a few instances in the website I have these includes or chunks of code/content that I would like to appear the same across the entire site. 

    So what I did is I made each chunk of code/content its own template.  So there’s a “Donate” widget and a “Register to Vote” widget set up as their own templates.  If I’m on our news page, for example, I want to install this “Donate” widget/content in one part of the page using the Publish or Edit page.

    But of course, when I put an {embed="site/donate"} in an entry field in Publish and Edit, EE renders the code instead of embedding a weblog.

    What am I missing here?  Is this not possible ...or do i need to insert some kind of special character to tell the Publish or Edit pages to render the EE Tag?

    Thanks!


    gm.

  • #2 / Jan 22, 2008 6:49pm

    Kyle Slattery

    109 posts

  • #3 / Jan 22, 2008 6:53pm

    GhostMeat

    2 posts

    Check out this plugin:

    http://expressionengine.com/downloads/details/allow_ee_code/

    Sweet, thanks.  Answers the question and provides the solution.  I dig it.

  • #4 / Apr 13, 2008 5:10am

    RezwanR

    126 posts

    Interesting.

    My website was migrated recently by the server, and I have been repairing it since then.  In doing so, I discovered that my {embed=x/y} tags don’t work anymore.  From this post it seems they were never supposed to, but I swear they used to work in my website before the migration.  I had tested them many times.

    My website sells magnets, and the bits that I embedded were simply buttons for people to purchase product.  The buttons work fine in the template, you can see them on every page (see http://ajabanzaban.com the “add to cart” buttons in the far right panel for each magnet kit)  But if you click the “see catalog” link, the entry has only {embed=bits/catalog} in it.  Trust me, when I first did this, I tested it a hundred times.  The bits/catalog thing has a list of the products again, and within that, some {embed=bits/buymagnet1} etc. for each product.  It used to work!  I sold things this way!

    Why isn’t it working now?  And since when has this required some kind of plugin?

    I’m questioning my sanity.

    Thanks!

  • #5 / Apr 13, 2008 11:40am

    Lisa Wess

    20502 posts

    Embeds worked in an older version of ExpressionEngine, but this was removed as it wasn’t intended that they work there, and posed somewhat of a security issue.  You could end up with someone embedding, say, your index template.  This just wasn’t a safe thing to do.

    So, now you can use the plugin mentioned above.  You may like to consider an alternative approach as well to avoid this kind of problem.  Perhaps a yes/no type field, or a drop-down with a list of embeds that you can use, then call those in your template instead.  This keeps things secure without giving up functionality.

  • #6 / Apr 13, 2008 11:52am

    Mark Bowen

    12637 posts

    As Lisa has mentioned and I would have to totally agree with 😉 it would be best if you had a drop-down custom field that simply has all the names of the embedded templates listed in it. You can then use conditional logic statements in your templates to spit out the correct template for that entry.

    {if template-to-embed == "widget-1"}
    {embed=widgets/widget-1}
    {if:elseif template-to-embed == "widget-2"}
    {embed=widgets/widget-2}
    {if:else}
    Standard widget to display if none chosen in drop-down menu
    {/if}

    This would require a custom drop-down field with a short name of template-to-embed which would have different choices in it. In this case widget-1 and widget-2 but you can call them however you like.

    This is of course if you want it different on every entry. If you just want a different embed based on where you are viewing at the moment i.e. which template then you would probably be better off just having conditional logic in the template that says which template to embed.

    Say you are on a news page and on all news pages irrespective of which news item you are viewing then you would just do this

    {embed=widgets/widget-1}

    or whichever widget template you want on the news page.

    Hope that helps a bit.

    Best wishes,

    Mark

  • #7 / Apr 13, 2008 12:27pm

    Lisa Wess

    20502 posts

    You don’t need that many conditionals.  Just have a None option, and compare to none - if none is selected, do nothing, if none is not selected, embed whatever is selected.  Only two conditionals and you can grow the drop-down at any time.

  • #8 / Apr 13, 2008 12:31pm

    Mark Bowen

    12637 posts

    EDIT - Won’t be apparent from the code that I posted above what I am getting at seeing as how my conditional matches my template name but that is what I meant anyway 😉

    Very good point. I only put it like that as sometimes the names that people choose for templates don’t look very nice in drop-downs. Each to their own I suppose but yes if you have nice looking template names then you don’t need that many conditionals.

    Also I don’t think you do need a none option do you? It’s a little weird but I have noticed (and this might just be me) but when you create a new entry, even if you have say option 1 selected in a drop-down it doesn’t actually get stored to the entry unless you actually click on the drop-down and then choose it. This may have been fixed / changed in previous releases but just something I remember that used to happen. Was always a bit weird actually as you could be wondering why an entry wasn’t showing up somewhere and when you go in to check the drop-down it would look right but the value hadn’t actually been stored in the database.

    But yes if the names of the templates are nice and neat then you can just use whatever value is in the drop-down.

    Best wishes,

    Mark

  • #9 / Aug 22, 2008 9:15am

    RezwanR

    126 posts

    Hey There!

    OK, I uploaded the plugin.  Checked to make sure it was there (e.g., I opened my utilities > plugin manager and there it is).  Then I went into my site/article template and put the code in the proper place, around the body tag, e.g.,

    {exp:allow_eecode}
    {body}
    {/exp:allow_eecode}

    But my {embed=...} is still not working.  I notice in the documentation it says:

    embed - (y/n) Allow you to allow the use of {embed} tags in your entries. Set to ‘n’ by default.

    but I don’t see where to switch from n to y.  It doesn’t really explain it well. 

    Any ideas?

    Thanks!

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

    Mark Bowen

    12637 posts

    Hi there I’ve never used that plugin so have no knowledge of its workings but what they mean is this sort of thing :

    {exp:allow_eecode embed="y"}
    {body}
    {/exp:allow_eecode}

    That should do it for you hopefully?

    Best wishes,

    Mark

  • #11 / Aug 22, 2008 9:40am

    Boyink!

    5011 posts

    Just my $0.02…but I’d also suggest an alternate design approach.

    You’re storing template logic in weblog posts, which buries them another couple of layers deeper in the system, make things harder to maintain and reverse-engineer down the road.

    You’re also opening up a means by which your client can mess up the site - if they go in to edit content and muck up the embed code, their donate button goes away and they don’t get $$....

    Much cleaner to have weblogs store content only, and do all the other stuff in templates.

    In a few instances in the website I have these includes or chunks of code/content that I would like to appear the same across the entire site.

    Why not just embed at the template level?

    Or as Lisa suggested - use a weblog field to trigger the decision, but then do the actual embedded in the template?

  • #12 / Aug 22, 2008 9:48am

    Mark Bowen

    12637 posts

    I meant to mention in my last post that what Michael has mentioned I would totally go along with. Much better to do this sort of thing at the template level rather than the weblog level. Things could very very quickly get out of hand. May not seem like it when you first go the route but at a later date you may find yourself having to place a lot of code into templates to work around what you have stored in weblog entries.

    Much better to keep code where it really should live - that being the templates. You can always have say a global variable and use that to embed a certain section / template into another template or even a weblog that holds an entry which says which template to embed but definitely leave the actual embedding of the code to the templates. It will be a lot easier to find and update code in the long run.

    Just my two penneths worth though 😉

    Best wishes,

    Mark

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

    RezwanR

    126 posts

    Hi Guys!

    Thanks Mark, the embed=y worked!  You’re a genius!

    OK.  About strategy. 

    The thing is that this is a language site, and you learn language through repetition.  So throughout the site I have these meta notes, a note for a word form or something, you hover over it, and you get a pop-up.  I want the note to be the same everytime, and so I don’t want to have to change the note in every post.  But also, people will encounter the posts in different orders, so I want them to always get the meta information.

    Using this post as an example:  http://www.ajabanzaban.org/index.php/site/article/word_order_sov/
    If you go down to

    1. The modifier comes before the word it modifies.

    The modifier comes before the word it modifies. Here is the phrase “Your Father”. From right to left, you read it “Pedar (e) Shoma

    If you hover over the e, a note pops up about what that is. 

    I want said note to pop up every time something like that shows up in a post, which it will in different contexts, with different phrases. 

    I suppose an alternative is to just have a web post about the ezafe and hyperlink to it.  It’s just that {embed=bits/ezafe} was so easy to remember and type.  With that, I could just put

    "Pedar {embed=bits/ezafe} shomA"
    it typed the e and everything.  I guess this isn’t much harder, you would just type in
    "pedar <a href="http://{path=x/y}33">(e)</a> shomA"

    or whatever.  That way I’d have to remember the number of the post, well, I guess I could still name it ezafe.  And also, some of the notes are very short.

    Yes, tell me about these global variables.  Maybe that’s another way for small notes that you want to have repeatedly pop up.

    Looking at my site, there are currently only 16 posts that have the embeddables. 

    As for shopping, it still seems useful to me to do it this way.  See this example:  http://www.ajabanzaban.org/index.php/site/article/pleasantries/ 
    Scroll to the bottom, I have the option to buy, or to donate, and also a popup on the little graphic there that explains what that phrase (“qAbel nadArad”) means.

    So…what do you think?

  • #14 / Aug 22, 2008 10:49am

    Boyink!

    5011 posts

    Ah - I need to apologize.  I completely missed that this was an older thread being resurrected and I replied to the original poster.

    Reading your use case, the only other idea that came to mind was the acronym plug-in.

    What I don’t like about the plugin is that it relies on a text file as it’s source.  It’d be nice - and more usable -  if someone took another stab at it and found a way to make the source file editable via the EE control panel.

  • #15 / Aug 22, 2008 10:53am

    Mark Bowen

    12637 posts

    There’s the other Acronym Module available at Solspace. That’s a pretty decent module actually. Might help out in this instance.

    Best wishes,

    Mark

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

ExpressionEngine News!

#eecms, #events, #releases