Copied to clipboard

Flag this post as spam?

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


  • Johan Roug 97 posts 153 karma points
    Aug 19, 2009 @ 00:38
    Johan Roug
    0

    remove HTML tags

    Hi I'm new here, and also new to Umbraco. I was wondering how to make Umbraco not Render my HTML tags in case a field is empty. Let me make an example.

    Here I have an Umbraco field which renderes. 

    <p><umbraco:Item field="teaser" recursive="true" runat="server"></umbraco:Item></p>

    But if the field in Umbraco is empty, the browser of cause render 

    <p></p>

     

     

    I can use this code instead, and the p tag will not render, but the code gets more messy.

     

    <umbraco:Item field="teaser" insertTextBefore="&lt;p&gt;" insertTextAfter="&lt;/p&gt;" runat="server"/>

     

    I know that I could just use XSLT instead with    ....if empty...bla bla

    But is there a smarter way to write my code??

     

    Thanks

     

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Aug 19, 2009 @ 09:00
    Thomas Höhler
    0

    You can also use some jQuery code to remove empty tags. So you don't have to care about these things on the templates or macros. If you want I can give you some sample code (have to search for it in my installations)

    Thomas

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Aug 19, 2009 @ 09:00
    Richard Soeteman
    0

    Hi,

    You could use the insertTextBefore and insertTextAfter attributes on umbraco:item. These will only be rendered when teaser has a value. see the example below. Make sure you html encode them or insert via the dialog box insert item in Umbraco

    <umbraco:Item field="teaser" insertTextBefore="&lt;p&gt;" insertTextAfter="&lt;/p&gt;" runat="server"></umbraco:Item>

    Hope this helps you,

    Richard

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Aug 19, 2009 @ 09:01
    Richard Soeteman
    0

    Example got messed up

    <umbraco:Item field="teaser" insertTextBefore="&lt;p&gt;" insertTextAfter="&lt;/p&gt;" runat="server"></umbraco:Item>

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Aug 19, 2009 @ 09:43
    Thomas Höhler
    101

    if you have included jQuery this should do it:

    <script type="text/javascript">
    $(document).ready(function() {
    $('p:empty').remove();
    });
    </script>

    This code removes all empty p tags from the DOM, but you can alos remove all empty tags by

    $(':empty').remove();

    hth,
    Thomas

  • Petr Snobelt 923 posts 1535 karma points
    Aug 19, 2009 @ 12:04
    Petr Snobelt
    0

    @thomas: I think removing empty tags should be done on server, not on the client.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Aug 19, 2009 @ 12:08
    Thomas Höhler
    0

    Agree, only another option if you are tired of typing too much (insertBeforeText...)

    ;-)

  • Petr Snobelt 923 posts 1535 karma points
    Aug 19, 2009 @ 12:14
    Petr Snobelt
    0

    You can create custom http module or handler, which remove empty tags.

    But insertTextBefore and after is good enough for me :-)

  • Johan Roug 97 posts 153 karma points
    Aug 19, 2009 @ 13:05
    Johan Roug
    0

    thank you.. I will try the jQuery, and also just stick to the imsert before and after code..

  • Muhammad hussain 33 posts 53 karma points
    Feb 02, 2011 @ 09:13
    Muhammad hussain
    0

    Hi

    I got help for this link. It is Nice to imliment

    I think your problem will be slove using this link

    http://our.umbraco.org/wiki/how-tos/customizing-the-wysiwyg-rich-text-editor-%28tinymce%29/allow-any-markup-in-the-tinymce-editor

     


    Thanks

    Muhammad Hussain

Please Sign in or register to post replies

Write your reply to:

Draft