Mura CMS: Hide menus for pages with restricted access

ColdFusion , Railo Add comments

I have just recently been playing with mura in the last 2 days which I decided to use for the new CFLIVE website.

One function I need is to have menus/pages which will only be visible to logged in users. While Mura does allow you to restrict access to pages, it still displays the menus/links and allows access to the page but gives a login prompt instead of the page content, I could not find any way to hide the menu links as well.
On the Mura forums even BlueRiver themselves have suggested the only option is to create a hard coded menu instead, which really seems like a terrible work around to me, although that reply was 5 years old, so perhaps there was no better way to do it back then.

Anyway  I found a better solution, but please be aware as I said, I have only been using Mura for 2 days, and have no more than a few hours experience with Mura code at this point, so if there is a better way of doing this, feel free to let me know.

Open the file /requirements/mura/content/contentRenderer.cfc

find the "allowlink function, around line 287 and copy this function to your site's contentRenderer.cfm
[site root]/default/includes/contentRenderer.cfc

now simply add the <cfelseif> block below, this will stop restricted pages showing in the menu if the user is not logged in.


<cfif  arguments.loggedIn and (arguments.restrict)>

                        <cfif arguments.restrictgroups eq '' or listFind(session.mura.memberships,'S2IsPrivate;#application.settingsManager.getSite(variables.event.getValue('siteID')).getPrivateUserPoolID()#') or listFind(session.mura.memberships,'S2')>
                                    <cfset allowLink=True>
                            <cfelseif arguments.restrictgroups neq ''>
                                    <cfset allowLink=False>
                                    <cfloop list="#arguments.restrictgroups#" index="G">
                                        <cfif listFind(session.mura.memberships,'#G#;#application.settingsManager.getSite(variables.event.getValue('siteID')).getPublicUserPoolID()#;1')>
                                        <cfset allowLink=true>
            <cfelseif !arguments.loggedin and arguments.restrict>
                <cfset allowLink=false>


5 responses to “Mura CMS: Hide menus for pages with restricted access”

  1. Melissa Says:
    Handy, thank you! It is weird that it's not a standard option.
  2. Tijn Snijders Says:
    This "contentrenderer.cfc" can be found in a few places.

    For instance, you can also find this file in your theme folder.

    MURA will check if that file exists in the "theme" folder, if so, it will use the functions in that contentRenderer.

    If it is not found in this theme folder, MURA will go 1 step higher, to the "themes" folder (the folder where all of your themes sit in). If so, MURA will use the functions in that contentRenderer.

    In case the contentRenderer isn't found in this themes folder, it will take the contentRenderer from the requirements folder.

    To not break anything in your application, best practice is to use the theme contentRenderer. Just put the functions in here you want to change, you do not have to make a complete copy of the requirements contentRenderer, any function that is not found will walk the same path as described above, to eventually be found in the requirements contentRenderer.

    The contentRenderer in your theme folder will not be overwritten by the MURA update process. It will only overwrite (if needed) the contentRenderer in the requirements folder.

    This way you can always update your MURA instance and not have to rewrite/re-add code :D
  3. Russ Michaels Says:
    Thanks tijn, I will update my article ordingly.
  4. Carl Says:
    Does not work for me.

    I'm trying it in the MuraFoundations theme. No results.

    Core 6.1.5896

    Thanks for posting the article though. I would like it if Blue River built this into the admin.

  5. Sebastiaan Says:
    Hi Russ?

    This took me some time to figure out as well, but now I have this setup straight out-of-the-Mura-box:

Leave a Reply

Leave this field empty:

Powered by Mango Blog. Design by Russ Michaels and inspired by styleshout