Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Robert 13 posts 33 karma points
    Nov 09, 2009 @ 20:28
    Robert
    0

    NEWBIE: Umbraco item in a page

    Thanks in advance for the help.

    I need to use an umbraco item in a page.

    This works fine in a template:

    <div>
    <p style="font-size:10px; line-height:normal;margin-left:50px">Current Version: <umbraco:Item field="newestEval32Version" runat="server"></umbraco:Item></p>
    </div>

    But, if I try to put the same directly in the HTML (using that feature of the editor), the "<umbraco:Item field="newestEval32Version" runat="server"></umbraco:Item>" gets stripped out.

    I suspect I need to modify the editor settings (somewhere) but have no clue where.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 09, 2009 @ 20:32
    Dirk De Grave
    0

    Robert,

    Do you mean you're trying to add the umbraco:item syntax to a rich text field, part of a document? If so, then yes indeed, it will be stripped out (that's the nature of tinymce and the way it's configured in umbraco - it tends to strip out invalid html)

    Could you tell us a bit more about what you're trying to do?

     

    Looking forward to your info

    Cheers,

    /Dirk

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Nov 09, 2009 @ 20:34
    Richard Soeteman
    0

    Hi Robert,

    You cannot use the umbraco:item tag in the HTML Editor. This will not get parsed. However you can use Macro'swith xslt or usercontrols  to display data and there is a select box on the macro which allows you to use the macro in the editor (Select from pull-down and fill in the parameters)

    Cheers,

    Richard

  • Robert 13 posts 33 karma points
    Nov 09, 2009 @ 20:48
    Robert
    0

    Thanks for the quick replies--much appreciated.

    I would like to incorporate an Umbraco item(s) in the text of a page. My wish is for the earlier example to render "Current Version: 4.9.0" (no quotes) when the value of the Umbraco item is "4.9.0" (no quotes).

    I have no idea on how to create a macro or user control (as Richard suggests).  So, an example wwould be great.

    I guess if I get one example, then I could modify it for other items(?).

    Otherwise, is there any way to tell tinymce that the code is valid?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 09, 2009 @ 21:33
    Dirk De Grave
    0

    Hi Robert,

     

    Here's how to create a macro and display a property from the current document being viewed on the frontend:

    -Go to developer section, right click xslt node and select create from the context menu. Select 'Clean' from template dropdown and check 'Create macro' as well. Enter a name for the xslt file (without extension) and hit Ok.

    -Copy 'n' paste next little xslt snippet underneath "<!-- start writing XSLT -->":

    Current version is:<xsl:value-of select="$currentPage/data [@alias = 'newestEval32Version']" />

    -Save your xslt.

    -Expand the macro node and find the macro with "same name" as your xslt. Check 'use in editor' as Richard has already suggested.

    -Go to your rich text editor field and click on the 'insert macro' button on the toolbar. Select your macro from the list.

    -Save and publish your work.

    -Browse your page -> you should get your version info on your page now

     

    Hope this helps.

    Regards,

    /Dirk

  • Robert 13 posts 33 karma points
    Nov 09, 2009 @ 21:55
    Robert
    0

    Thanks, Dirk.

    I tried that and get the "Current version is:" but not the version number.  I know the value is in that variable because it works in the template but not on a page that uses the macro.

    What should I look for next?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 09, 2009 @ 22:14
    Dirk De Grave
    0

    Robert,

    Can you add following snippet in your xslt file:

    <textarea><xsl:copy-of select="$currentPage" /></textarea>

    above or below the xsl:value-of statement.

    What output do you get then?

     

  • Robert 13 posts 33 karma points
    Nov 09, 2009 @ 22:43
    Robert
    0

    I can try that but I think the issue is that the item is not "connected" to the page I'm trying to use it on. I will test that notion. But, I think I need to get the info from another page somehow in the macro.  Will be back after I try that.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 09, 2009 @ 22:54
    Dirk De Grave
    0

    Robert,

    Ok, let's make some changes to the system:

    -Expand the macro node in the developer section, select your macro and go to 'Parameters' tab. Add a new parameter (alias is what will be used to reference it) of type number (for simplicity). Make sure to mark 'Show' and save your work.

    -Go back to where you're using the macro on, remove it, and re-insert it using the 'insert macro' dialog. Select macro from list, and click Ok. you should be able now to enter the value for the numerical parameter. Enter the id of the node that has the newestEval32Version property!

    -Change xlst

    Current version is:<xsl:value-of select="umbraco.library:GetXmlNodeById($nodeId)/data [@alias = 'newestEval32Version']" />

    and add a parameter 

    <xsl:variable name="nodeId" select="/macro/alias" />

    'alias' should be replaced with the alias you've entered when creating the parameter on the macro. Above snippet should be entered below the

    <xsl:param name="currentPage" />

     

    Run again and let us know how that works out!

     

    Cheers,

    /Dirk

  • Robert 13 posts 33 karma points
    Nov 09, 2009 @ 23:19
    Robert
    0

    Perfect!  Thanks again for the help. I hope someone else benefits from this thread--I knew it could be done.

    Now, I know how to take advantage of many other items we're storing.

  • Robert 13 posts 33 karma points
    Nov 09, 2009 @ 23:31
    Robert
    0

    I tried to give Dirk's very helpful post a vote but only get a yellow box with a "close" on it.

Please Sign in or register to post replies

Write your reply to:

Draft