- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2015 09:39 AM
I'm attempting to include a dynamic content block in a layout via <g:content_block type="content_block_programmatic" id="c29676280f1e8600116be388b1050e50"/> in order to have it appear across an entire site (preventing me from having to add it to every page on the site manually). However, both the contents of the dynamic content block and the condition don't seem to be evaluating properly.
The condition is simply to display the block only if a user is signed in, and looks like:
function userNotLoggedIn() {
if(gs.getUserName() === "guest") {
answer = true;
} else {
answer = false;
}
}
userNotLoggedIn();
whereas the dynamic content gets some URL parameters in order to allow for a redirect post-authentication:
<g:evaluate var="jvar_site_and_page" jelly="true">
var page = new GlideRecord('content_page');
page.get('${RP.getParameterValue('sysparm_sys_id')}');
page.content_site.url_suffix + '/' + page.url_suffix;
</g:evaluate>
When the block is simply added to a page like other content, everything functions perfectly. It's only when I use the g:content_block method of rendering the block that things don't seem to work as they should.
Any suggestions? I'm not entirely sure that I'm even going about this problem in the right way, but I'm really looking for a way to not need to manually add this block to every single page in the site.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2015 10:45 AM
I don't think it will evaluate your condition if you include it hardcoded in the layout, so I would just add an if statement directly in your layout. Something like:
<j:if test="${gs.getUserName() === 'guest'}">
<g:content_block type="content_block_programmatic" id="c29676280f1e8600116be388b1050e50"/>
</j:if>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2015 10:45 AM
I don't think it will evaluate your condition if you include it hardcoded in the layout, so I would just add an if statement directly in your layout. Something like:
<j:if test="${gs.getUserName() === 'guest'}">
<g:content_block type="content_block_programmatic" id="c29676280f1e8600116be388b1050e50"/>
</j:if>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2015 05:11 AM
Thanks! After fixing some bugs of my own, this ended up doing exactly what I needed it to.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2016 08:56 AM
I am facing the same issue. How did you end up passing "RP.getParameterValue()" to your hardcoded block on the layout?