Copied to clipboard

Flag this post as spam?

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


  • pbl_dk 150 posts 551 karma points
    Apr 21, 2015 @ 22:08
    pbl_dk
    0

    Problem with RTE and htmlraw umbraco 7.2

    Hello All!

    I am trying to format a rich text editor text with a simple query, but nothing works. I have tried many combinations:

    I have been trying to create a partial view meta in 7.2 like this:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @Html.Raw(CurrentPage.summary);

    Output is:<meta name='description' content='&lt;p&gt;

    I need to strip the <p> tags.

    Nothing really works for me, any hints?

    thanks!
    /Peter


     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 21, 2015 @ 22:15
    Jan Skovgaard
    1

    Hi Peter

    May I ask why you don't use a textbox multiple field for the meta description instead? It's not that the HTML tags can't be stripped but sounds to me like you're using the same summary field for your meta description as you're using for your summary, which I suspect is displayed as a part of your page rendering as well? If so then i suspect that this will also be longer than 155-160 characters, which should be maximum for the meta description.

    So perhaps the real solution will be to use a specific meta description field instead?

    Technically you should be able to use Regex.Replace to have the HTML tags removed - Try seeing the example posted on SO here http://stackoverflow.com/questions/11734877/remove-html-formatting-in-razor-mvc-3

    EDIT: Added the link to the SO post

    Hope this helps.

    /Jan

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Apr 21, 2015 @ 22:21
    Dennis Aaen
    102

    Hi Peter,

    I think you can use the StripHTML method, with this method you are stripping the HTML.

    Take a look here https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/#StripHtml%28stringhtml%29

    I also think that you could use a normal @Umbraco.Field in your template. It will looks like this:

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

    Remember to change title so it match your alias of the field for the meta description.

    Hope this helps,

    /Dennis

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 21, 2015 @ 22:22
    Jan Skovgaard
    0

    Aaah yeah, totally forgot about that section in the documentation! H5IS :)

    /Jan

  • pbl_dk 150 posts 551 karma points
    Apr 22, 2015 @ 09:17
    pbl_dk
    0

    It worked so nicely with removeParagraphTags!

    Thank you guys, you are so fast on this forum!

    @Jan : the reason is, that summary on the website is limited to 155 chars, even though, summary are to be shown on the frontpage. I saw that most newspapers has a limited "snippet" of text on the frontpage, I wanted to make it the same way.
    I have made the rule, that if meta description field is empty in the backend, then umbraco will use "summary" instead. that should make it easier for the editor. Also editor can then decide whether he needs to SEO the field separately or just use summary.
    I am trying to cut down on fields, that the editor must remember to fill out.

    Thank again for the help!

    I think, I need to dig into the difference between @umbraco, @model and @currentpage. I can not seem to find out, when to use what..


    Have a nice day!
    /Peter
     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Apr 22, 2015 @ 09:32
    Dennis Aaen
    0

    Hi Peter,

    I would try to explain when to use @umbraco, @model and @currentpage. and the differences.

    In Umbraco we have to implementations of Razor one is called the dynamic version and one called strongly typed version. If you are using the dynamic version of Razor, then you can get the current page your are on by using @CurrentPage. If you are using strongly typed Razor then the current page is @Model.Content.

    Here are some good Razor cheatsheet, that shows some of the differences and methods in Razor. I know it says for Umbraco 6, but you can use it in 7 too. It´s some pdf files. https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets Other documentation on this can you find here: https://our.umbraco.org/documentation/Reference/Mvc/partial-views and https://our.umbraco.org/documentation/Reference/Templating/Macros/Partial-View-Macros/

    @Umbraco is using when you need to use a Umbraco helper https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/ it could be that you need to get a specific page  on it´s id. @Umbraco.Content(1234) is the dynamic version, and the stronly typed looks like this @Umbraco.TypedContent(1234).

    When you are working with the property editors in Umbraco you can use dynamic Razor or Strongly typed Razor as I was have mentioned, here is the documentation for each of the property ediors https://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/Built-in-Property-Editors-v7/. If we are taking the example of using the content picker, then you can see there is an example of both implementations of Razor. https://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/Built-in-Property-Editors-v7/Content-Picker

    Hope this can help you.

    /Dennis

  • pbl_dk 150 posts 551 karma points
    Apr 22, 2015 @ 16:31
    pbl_dk
    0

    Hi Dennis,

    Thank you! I have bookmarked them all. I guess those pages will be my future working papers from now on.

    Can you briefly point out, why CurrentPage is Dynamic vrs the Strongly Type? I can't see the difference. Is there specific thing not allowed in CurrentPage, or when would you use dynamic vrs stongly typed?

    Thank you so much for this!
    /Peter
     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Apr 22, 2015 @ 16:55
    Dennis Aaen
    0

    Hi Peter,

    The differences is that, when you are using the Dynamic Razor the syntax is more concise, and with Strongly typed Razor you are getting intellisense when you are writting your Razor code if you are using e.g Visual Studio or another text editor with intellisense, e.g the WebMatrix from Microsoft.

    Hope this answers your question.

    /Dennis

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 22, 2015 @ 17:13
    Jan Skovgaard
    0

    Hi Peter

    Just want to add the following...

    In regards to the naming of "CurrentPage" it could just as well have been "Current" or something else - But it's been named "CurrentPage" since people who have been using Umbraco for a long time, even before Razor made it's way into the core, are used to XSLT where there is a $currentPage parameter that makes it possible to fetch the data from the page one is currently on. So it's an effort to try and make the transition between the two technologies easier and to keep the naming convention to avoid too much confusion about things.

    Otherwise I think you might be able to benefit from Jeavon Leopold's slides from the Umbraco festival in Germany here http://www.slideshare.net/JeavonLeopold/umbraco-oktoberfest-2014 - He explains about Razor in Umbraco and is getting into some of the differences and details of dynamic vs. strongly typed.

    EDIT: Also I think that using dynamic is a bit like JavaScript, which is a weakly typed language, which means you don't have to specify that a certain variable is a number or a string like you would in a strongly typed language / strongly typed view. At least that's my understanding and how I keep reminding myself about the differences (And I hope someone will correct me if I'm wrong) :)

    Hope this helps.

    /Jan

  • pbl_dk 150 posts 551 karma points
    Apr 23, 2015 @ 09:45
    pbl_dk
    0

    ahh makes sense now Jan. Yes I know currentpage from XSLT I see the connection.


    Thank you both, so much for being so helpful !!

     

    Have a nice day!
    Peter
     

Please Sign in or register to post replies

Write your reply to:

Draft