Copied to clipboard

Flag this post as spam?

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


  • SiKo279 82 posts 238 karma points
    Jul 05, 2009 @ 12:27
    SiKo279
    0

    How to insert a document type propery into the content part of a node?

    Hello all,

     

    I've defined a 'phone number' property on a document type.

    I'd like to have the user to be able to insert the value of this property into the text he/she is editing in the bodytext of the same page.

    I saw how to insert this property into a template, but the user should be able to insert it where ever is appropriate.

    I tried with a macro, but that didn't result in any output.

    The idea behind this is that whenever a phonenumber needs to be changed, it can be changed on the top node and all the child nodes that use the value (in their editable bodytexts), should recursively use that value.

    Any ideas on how to achieve this?

     

    Thanks

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jul 05, 2009 @ 14:35
    Aaron Powell
    0

    What was the problem you had when you were doing it via a Macro, that's how I'd do it. I'd have the macro either as an XSLT which just has something like this:

    <xsl:select value-of="$currentPage/data[@alias='phone_number']" />

    (Ok, that should be close, XSLT was never my strong point)

    Or you can use the nodeFactory API to get it, using the UmbracoContext.Current.PageId property to constructor so it gets the right one.

  • SiKo279 82 posts 238 karma points
    Jul 05, 2009 @ 14:52
    SiKo279
    0

    The problem is that the macro is not showing any value.

    Another feature is that I want to specify the value of phoneNumber only on the top node and where ever it is referenced, it should recursively retrieve the value.

    I was looking for the xslt reference but I can not find it anymore... :(

  • SiKo279 82 posts 238 karma points
    Jul 05, 2009 @ 15:23
    SiKo279
    0

    Ok, adding $currentPage makes it render, only if the number is specified on the current page.

    Maybe I can 'hard code' the xslt to look on the root node?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 12x admin c-trib
    Jul 05, 2009 @ 15:24
    Jan Skovgaard
    3

    Could you please provide some examples of your structure and the code you are using now? I think it would be easier to help you out when one can see what you are doing :)

    First we need to find out why you are not getting any value from the field in your xslt macro.

    It should not be a problem fetching the value recursively - I would think that you can use something like this to do it

    <xsl:value-of select="$currentPage/ancestor-or-self::node/data[@alias='phone number']" />
  • SiKo279 82 posts 238 karma points
    Jul 05, 2009 @ 15:33
    SiKo279
    0

    Jan and Slace, great stuff, this -=almost=- solved the problem.

    Now it is recursively getting the number and the user is able to insert it into the text.

    The only thing that remains is that the macro is wrapped in a <div></div> block and that inserting it closes the <p> tag and opens a new one after. This implies that the user needs to go to the html editor to fix this.

    Is there a way to not have the macro wrap its output in <div> tags?

  • SiKo279 82 posts 238 karma points
    Jul 05, 2009 @ 15:50
    SiKo279
    0

    Another problem just discovered: the macro renders it's content and stops being a macro, meaning that next time the value is not looked up anymore.

    Maybe I'm just a bit confused.

    Here's what I have: Master Doc Type with property: phoneNumber (alias)

    Node based on child of the Master Doc Type, but the property is given a node above (root node).

    <

     

    <

     

    <

     

    </

     

  • SiKo279 82 posts 238 karma points
    Jul 05, 2009 @ 15:50
    SiKo279
    0

    sorry about the mess,

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
     <xsl:value-of select="$currentPage/ancestor-or-self::node/data [@alias = 'phoneNumber']"/>
    </xsl:template>

  • Jan Skovgaard 11280 posts 23678 karma points MVP 12x admin c-trib
    Jul 05, 2009 @ 15:56
    Jan Skovgaard
    0

    To wrap your stuff up in a <div> tag and a <p> tag you just need to put it in your XSLT like this

    <div>
    <p>
    <xsl:value-of select="$currentPage/ancestor-or-self::node/data [@alias = 'phoneNumber']"/>
    </p>
    </div>
  • SiKo279 82 posts 238 karma points
    Jul 05, 2009 @ 16:06
    SiKo279
    0

    I want the output to be inside a <span> tag, the macro:

    <xsl:template match="/">
        <span>
            <xsl:value-of select="$currentPage/ancestor-or-self::node/data [@alias = 'phoneNumber']"/>
        </span>
    </xsl:template>

    but still, the output is inserted in a <div> tag and in the wrong place:

    <p><strong>Call us at I INSERTED HERE</strong> to .... some more text</p>
    <!-- AND THIS IS WHERE IT APPEARED -->
    <div ismacro="true" umbversionid="7a8b63ff-28a6-44a2-819f-8ee47f3e5567" umbpageid="1103" umb_macroalias="insertPhoneNumber" onresizestart="return false;" title="This is rendered content from macro" class="umbMacroHolder"><span>This macro does not provides rendering in WYSIWYG editor</span><!-- endUmbMacro --></div>

  • Jan Skovgaard 11280 posts 23678 karma points MVP 12x admin c-trib
    Jul 05, 2009 @ 16:26
    Jan Skovgaard
    0

    hmm ok that part I don't know to much about...I'm not to sure what is going on when you use macros in the RTE. I hope there are some others that can give an answer to that :)

  • Jesper Hauge 298 posts 487 karma points c-trib
    Jul 05, 2009 @ 23:28
    Jesper Hauge
    1

    Just tried this on a fresh Umbraco 4.0.2.1 install, what version are you on?

    It's true that the inserted macro renders the <div ismacro="true ...> code when checking the code via the HTML button in the editor. But the output in the actual front-end page doesn't contain the html-code. It only renders a <span>content</span> as it should.

    Regards
    .Hauge

  • Mikael Mørup 297 posts 326 karma points
    Jul 06, 2009 @ 09:21
    Mikael Mørup
    0

    This is because you can't have a <div> tag inside a <p> tag in strict XHTML.

    I had similar problems with trying to insert HTML "snippets" with macros.

    I never really found a satisfying solution.

    I believe that you can program your own extension to TinyMCE, i looked at it, but havent had the time to do it yet.

  • SiKo279 82 posts 238 karma points
    Jul 06, 2009 @ 09:50
    SiKo279
    0

    I'm using version 4.0.2.1 ...

    With some editing, (putting the div tag inside the p tag, which is not optimal), the phonenumber is displayed.

    So I have to join Mikael and be at least a bit unsatisfied with the solution as-is ... but this topic is solved!

    Thanks to all for contributing.

  • SiKo279 82 posts 238 karma points
    Jul 06, 2009 @ 09:57
    SiKo279
    0

    How can I close this topic?

  • Jesper Ordrup 1019 posts 1528 karma points MVP
    Jul 06, 2009 @ 11:06
    Jesper Ordrup
    2

    Another approach useful for merging data from anywhere into your bodyText. The goal is to be able to use the richtext editor and insert mergefields. The  like this:

    Hello [memberName],

    Your are welcome to contact us on [companyPhoneNumber]

    Regards

    [companyContact]

     

    To make that work make an xslt extension that finds the mergefields and fetches the data:

    On the template you then need to use the extension like this:

    <xml:value-of select="merger:MyMergeMethod($currentPage/data [@alias='bodyText])"/>

     

    /Jesper

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 06, 2009 @ 11:14
    Dirk De Grave
    100

    @siko279: you don't close topics, you just mark post that was most useful as the answer. It might not be an 'answer' as in 'oh, that post does really solve my problem', it could quite easily be a 'suggestion' that got you on the right track!

     

    Cheers,

    Dirk

     

  • SiKo279 82 posts 238 karma points
    Jul 06, 2009 @ 12:16
    SiKo279
    0

    @jesper ordrup: Thanks for that... good suggestion.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies