Copied to clipboard

Flag this post as spam?

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


  • Jim Taylor 20 posts 43 karma points
    Jan 20, 2012 @ 12:53
    Jim Taylor
    0

    Umbraco V5 - Macro - Pull Child Page Content into Parent Page

    I have a Testimonials Page with each Testimonial as a child page.
    I need to pull each Testimonial into the Testimonials Page.

    The only content/fields I'm pulling is testimonialQuote and testimonialName.

    I'm used to doing this in XSLT, but with Umbraco 5 dropping it for Razor, I'm stuck.
    I've created a Macro and Macro Partial and rendor the file:

    @Umbraco.RenderMacro("testimonials")

    But what do I put in the Macro Partial's file?

    I need to create:

    <div id="testimonials">

    <div class="testimonial">
    <div class="quote"></div>
    <div class="name"></div>
    </div>

    <div class="testimonial">
    <div class="quote"></div>
    <div class="name"></div>
    </div>
    <div class="testimonial">
    <div class="quote"></div>
    <div class="name"></div>
    </div>
    </div>

     

  • Andrew Hawken 59 posts 116 karma points c-trib
    Jan 22, 2012 @ 23:43
    Andrew Hawken
    0

    I'd do something like this

     

    <divid="testimonials">

     

    @foreach (var item in DynamicModel.Children)

      {

    <div class="testimonial">

    <div class="quote">@item.testimonialQuote</div>

                     <div class="name">@item.testimonialName</div>

            </div>

      }

    </div> 

     

     

     

     

  • Jim Taylor 20 posts 43 karma points
    Jan 23, 2012 @ 09:29
    Jim Taylor
    0

    Thanks Andrew,

    Unfortunately I'm getting a server error in :/
    Can anyone test this V5?

    @inherits PartialViewMacroPage
    @using Umbraco.Cms.Web
    @using Umbraco.Cms.Web.Macros
    @using Umbraco.Framework

    <div id="testimonials">

    @foreach (var item in DynamicModel.Children)
    {
    <div class="testimonial">
    <div class="quote">@item.testimonialQuote</div>
    <div class="quote">@item.testimonialName</div>
    </div>
    }
    </div>
  • Dan Virsén 9 posts 29 karma points
    Jan 23, 2012 @ 13:18
    Dan Virsén
    0

    This works for me in V5. What kind of error do you get?
    Looks like it's something in the references at the top that's giving you trouble, since that's all I changed.

    But I'm not that experienced with Umbraco at all, so I have no idea what's really causing the error.

    @inherits RenderViewPage
    @using Umbraco.Cms.Web;

    <div id="testimonials">
    @foreach (var item in DynamicModel.Children)
    {
    <div class="testimonial">
    <div class="quote">@item.testimonialQuote</div>
    <div class="quote">@item.testimonialName</div>
    </div>
    }
    </div>
  • Jim Taylor 20 posts 43 karma points
    Jan 23, 2012 @ 14:43
    Jim Taylor
    0

    Ar, it works as a normal Partial and added to the Template.

    I was creating a Macro Partial and Macro and then adding the macro into the rich text editor...

     

    Thanks guys!

     

  • Andrew Hawken 59 posts 116 karma points c-trib
    Jan 23, 2012 @ 14:50
    Andrew Hawken
    0

    What build are you using? I can't get RTE insert to work with surface controllers in Fridays nightly (see http://issues.umbraco.org/issue/U5-274?projectKey=U5) it used to work though!

    BTW how do I insert pretty code in this forum...??

     

  • Jim Taylor 20 posts 43 karma points
    Jan 23, 2012 @ 15:02
    Jim Taylor
    0

    Is there a way to remove the paragraph tags? I'm using a Rich Text Editor for the Quote.

    I need to add removeParagraphTags: true to .quote

    @inheritsRenderViewPage
    @usingUmbraco.Cms.Web;

    <div id="testimonials">
    @foreach(var item inDynamicModel.Children)
    {
     
    <div class="testimonial">
       
    <div class="quote">@item.testimonialQuote</div>
        <div class="name">@item.testimonialName</
    div>
     
    </div>
    }
    </
    div>
  • Dan Virsén 9 posts 29 karma points
    Jan 24, 2012 @ 10:50
    Dan Virsén
    0

    Oh, I see I misunderstood what you were doing and what you wanted to do in the first place. Sorry :)
    I didn't get any errors when I created a new macro/macro partial and pasted Andrews code into it unfortunately, so I don't know why you got the error.

    Regarding your last question, all I could find was this:

    @Umbraco.Field("testimonialQuote", removeParagraphTags: true)

    But that only removes the first "<p>", so at the very least you get an extra "</p>" after the field value...
    If you have more paragraphs they get rendered with paragraph tags. This really seems like a bug though.

    Since it's a quote, couldn't you use the simple editor or just a textbox for the text?

    Sorry I can't help more then that, but I found these on the subject (haven't read them though):
    http://our.umbraco.org/forum/developers/razor/19379-Remove-paragraph-tags-with-razor
    http://stackoverflow.com/questions/7122802/how-to-remove-html-tags-from-rich-text-editor-in-umbraco-razor ;

     

    @Andrew: Select the code snippet and change the format from Paragraph to Preformatted.

  • Marco Pietersen 6 posts 27 karma points
    Feb 24, 2012 @ 16:57
    Marco Pietersen
    1

    If people are still wondering:

    @Html.Raw(item.testimonialQuote)

    will paste the content's HTML

     

  • Lars Corneliussen 2 posts 22 karma points
    Mar 31, 2012 @ 15:18
    Lars Corneliussen
    0

    Actually, even better:

    @Umbraco.Field(item, "testimonialQuote")

    It will then use the FieldRenderer, which in turn also renders embedded macros, e.g.

    I'm not sure if this works with DynamicModel.Children, though; I'm using Model.Children...

  • Sam dalton 5 posts 25 karma points
    Dec 18, 2012 @ 06:19
    Sam dalton
    0

    has anyone got a solution of this same issue in XSLT

Please Sign in or register to post replies

Write your reply to:

Draft