Copied to clipboard

Flag this post as spam?

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


  • Aximili 177 posts 278 karma points
    Oct 06, 2011 @ 04:24
    Aximili
    0

    How to hide Preview button on documents with no templates

    If a document has no template, clicking preview will show the "intentionally ugly" error page.

    I do have a lot of items with no template (eg. News item, Downloadable file, etc).

    How do I hide the preview button on these documents?

    Thanks in advance!

  • Markus Johansson 1909 posts 5733 karma points MVP c-trib
    Oct 06, 2011 @ 06:54
    Markus Johansson
    0

    Sounds like a lot of job for this little feature, you probably need to change the core and look at the loaded node if it has a template, if not modify the buttons-property of the TinyMCE-plugin. Or dose anyone else know a better way to solve it?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 06, 2011 @ 09:06
    Dirk De Grave
    0

    yup, can't do without touching the core, unless you fiddle around with jquery and "hide" the preview button based on the values in the templates dropdown list. For some inspiration have a look at this package (not for production use, but shows how to do some stuff in the backend without touching the core)

    Cheers,

    /Dirk

  • Aximili 177 posts 278 karma points
    Oct 07, 2011 @ 02:13
    Aximili
    0

    Dirk, thanks! I am really interested to hide it using jQuery. I looked at the source of that package but I don't get it. Would you mind telling me how to do it or is it something very hard?

  • Markus Johansson 1909 posts 5733 karma points MVP c-trib
    Oct 07, 2011 @ 07:48
    Markus Johansson
    0

    You could check if the current page has any template and based on that insert this code:

    $(document).ready(function() {
      // Hide element
     $("body_T1_cut").hide();
    });

    But i'm not sure how to hook in to the edit content page? An ugly way would be to make a custom data type that readerns the jQuery, but it sounds like dirty coding to me!

    @Dirk - Do you have any ideas?

     

  • Aximili 177 posts 278 karma points
    Oct 07, 2011 @ 08:36
    Aximili
    0

    Thanks Markus! Where am I supposed to put in that javascript?

    I mean, this is an Umbraco page, not a custom section or anything...

  • Markus Johansson 1909 posts 5733 karma points MVP c-trib
    Oct 07, 2011 @ 11:49
    Markus Johansson
    0

    We are talking about this page: /umbraco/editContent.aspx?

    As you say, it's an Umbraco page and a part of the core framework so changing it is not a good idea. I'm not sure if my approch is good but I think it may work. If you make a custom datatype and insert in the current document you will be able to run the code when editContent.aspx loads without changing the core. This may not be the best way, I'm not sure.

    More on custom datatypes: http://www.nibble.be/?p=50

  • Aximili 177 posts 278 karma points
    Oct 10, 2011 @ 02:07
    Aximili
    0

    Thanks Markus! Alright, I just hacked it in into umbraco/editContent.aspx. It seems to work.

    This is what I added:

        <script>
            $.expr[":"].econtains = function (obj, index, meta, stack) {
              return (obj.textContent || obj.innerText || $(obj).text() || "") == meta[3];
            }
            $(function () {
              var ddlTemplate = $("div.propertyItemheader:econtains('Template')").next().children('select');
              if (ddlTemplate.length > 0) {
                var templateValue = $(ddlTemplate[0]).val();
                if (templateValue == '')
                  $("img[title='Preview']").hide();
              }
            });
        </script>

  • Murray Roke 503 posts 966 karma points c-trib
    Sep 01, 2015 @ 22:32
    Murray Roke
    0

    For umbraco < 7 you could also use this to inject your custom script:

    https://our.umbraco.org/projects/backoffice-extensions/backoffice-power-scripts/

    I'd like to do this in umbraco 7, any ideas?

Please Sign in or register to post replies

Write your reply to:

Draft