Copied to clipboard

Flag this post as spam?

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


  • Alex 21 posts 41 karma points
    Aug 10, 2010 @ 19:26
    Alex
    0

    Inserting small piece of data into content

    Hi all,

    I'm new to Umbraco so please be gentle!

    I have the need to insert a small piece of data - for example a telephone number retrieved from a .NET session variable - into content. I tried doing this by using a User Control macro but when inserting the the macro into the RTE the CMS decided to use a <div>. I don't want the phone number to be in a block level element, in fact I want it to be inside a <p> tag. How do I change the this macro <div> to something better, like a <span> ?

    Should I even be using a macro to do this? Is there a better way to insert snippets of data like this into content? 

     

    Many Thanks,

    Alex

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Aug 10, 2010 @ 20:16
    Morten Bock
    0

    I never found a really good, simple, way of doing that. As you mention, the macros don't work well when trying to write inline text. What I would tend to do is to make some sort of syntax for inserting text snippets like {{phoneNumber}} and then either do some replacing in the template, or maybe even hook in a httpModule to parse the entire html output for placeholders, and inserting the correct data.

    So the solution depends a bit on what sort of development you want to be doing.

  • Bogdan 250 posts 427 karma points
    Aug 10, 2010 @ 20:19
    Bogdan
    0

    Hi Alex,

    I don't know how you can change the <div> into something else. Inserting the macro in the rte is one way of doing this, but you can also make an xslt macro that both reads the session variable (the Umbraco.Library xslt extension has a Session method) and inserts the text in the page. Then put the macro in the template. This way you have full control over the markup. Let me know if you need more help on how to do this. About the <div> added by the rte you can maybe do some research in the folder umbraco\plugins\tinymce3 or umbraco_client\tinymce3\plugins\umbracomacro.

  • Bogdan 250 posts 427 karma points
    Aug 10, 2010 @ 20:58
    Bogdan
    0

    I've just made a test in umbraco 4.5.1 and I don't see a div around the inserted macro's content. I did try with an xslt macro though. Maybe worth a try!

  • Alex 21 posts 41 karma points
    Aug 10, 2010 @ 21:59
    Alex
    0

    Thanks for your speedy responses!

    bfi - sorry I wasn't clear.. the macro itself is represented by a div element in the rte, which is annoying because when I insert a macro within a paragraph tag tinymce will close the paragraph tag as it's trying to hold my hand and make me adhere to the proper standards. I've done a bit of Googling and it appears I can't change Umbraco to use a different tag to represent macros (or it's not straightfoward to do!). I may have a look at an xslt macro though, so thanks for that.

    Morten -  inserting {{telephone}} in the content might work for me, and I think my client would be happy to write that wherever they needed the telephone number. Where, within the Umbraco site structure, would I have to write my replacement code? I'd rather not have to create an httpModule if possible.

  • Alex 21 posts 41 karma points
    Aug 11, 2010 @ 14:48
    Alex
    0

    Any ideas on the {{tag}} replacement stuff? Has anybody written this before for Umbraco?

  • Bogdan 250 posts 427 karma points
    Aug 11, 2010 @ 14:58
    Bogdan
    0

    Well I'll try to answer that, hopefully Morten won't mind :) You can make an xslt macro where you read the text that contains the {{telephone}} string

    <xsl:variable name="myText" select="xpathToTheTextAlias" />

    you make another var that holds the value of the phone number

    <xsl:value-of name="phoneNumber" select="doStuffHereToGetTheValue" />

    then replace {{telephone}} with $phoneNumber

    <xsl:value-of select="umbraco.library:Replace($myText, '{{telephone}}', $phoneNumber)"/>

    Let me know if this works.

  • Alex 21 posts 41 karma points
    Aug 11, 2010 @ 15:05
    Alex
    0

    Thanks for the quick reply. I actually want to do this site wide, so don't want to have to put the replacement xslt code in each and every template. Do you know if this is possible?

  • Alex 21 posts 41 karma points
    Aug 11, 2010 @ 17:31
    Alex
    0

    Am I going to have to use an httpModule, or is there any other way?

  • Alex 21 posts 41 karma points
    Aug 11, 2010 @ 18:22
    Alex
    0

    Actually decided to do the token replacement in a Global.asax file. Do you happen to know of a good way to check if the HttpRequest is for the front-end Umbraco site and not the back-end admin area? Bearing in mind the umbraco folder has been renamed (ie. I don't want to rely on determining if it's the admin area via the URL)

  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    Aug 11, 2010 @ 18:24
    Sebastiaan Janssen
    1

    The umbraco folder name is actually in the web.config and needs to be changed if you move it, so you could rely on that just fine.

  • Alex 21 posts 41 karma points
    Aug 11, 2010 @ 18:34
    Alex
    0

    Superb idea, I can use the "umbracoPath" element in web.config.

    Seems to work a treat. I'm checking if the value of that umbracoPath element is at the start of the Request.Url.AbsolutePath variable using indexOf(). If it is I don't do the text replacement because I know the request is for the admin area. Sweet.

    Thanks you all for your help!

  • Heather Floyd 605 posts 1004 karma points MVP 5x c-trib
    Sep 15, 2011 @ 17:28
    Heather Floyd
    0

    Alex,

    This is something I have been trying to figure out how to do also - though in my case the data would be pulled from Dictionary Items. Is there any chance you might be able to share some snippets of your Global.ascx code?

    Thanks so much!

    Heather

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Sep 15, 2011 @ 18:57
    Morten Bock
    0

    There are a couple of ways to do this now.

    One is to use the shortcodes package.

    Another is to take the approach that I did here: Using inline macros in the Umbraco editor

    Hope this is useful :-)

  • Heather Floyd 605 posts 1004 karma points MVP 5x c-trib
    Sep 19, 2011 @ 21:38
    Heather Floyd
    0

    Thanks, Morten,

    Great stuff. I will need to figure out if it would work with my circumstance.

    What I want to do is to be able to use the "Dictionary" like a repository of "constants" for the website (so we have a single place to update a value across the website - like "number of customers", which might be 200,000 today, but next month is 250,000, or whatever)... so inside the RTE or templates, we could put in something like [*NumCustomers] , and when it is displayed on the website, it would dynamically replace "[*NumCustomers]" with the current number from the Dictionary, using the current culture, and the key "NumCustomers"...

    Your inline macro thing looks great - except that it seems I wouldn't be able to pass in the dictionary key... right? So I would in essence have to create a different macro for each possible "constant"...? (Probably not ideal)

    The shortcodes package operates the way I would like, but I will need to figure out how to program a REST extension (something I haven't done before) and right now the site is version 4.6...

    I appreciate you pointing me towards these resources, though.

     

     

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Sep 20, 2011 @ 09:17
    Morten Bock
    0

    I think you could do just one macro, but then you would do a TinyMCE snippet for each dictionary key, where it is defined as a parameter to the macro in the snippet.

    Another option would be to take a looke at the source for Shortcodes, and take a look at the http module that does the replacing. You might be able to "roll your own" specifically for your needs. (Or maybe it's already in there, but just no shown in the samples)

Please Sign in or register to post replies

Write your reply to:

Draft