ExpressionEngine conditional logic with related_entries - expressionengine

{if taxonomy != "" OR related_pages != "" OR related_posts != "" OR related_news != ""}
<footer role="contentinfo">
{if taxonomy != ""}
<div id="taxonomy" itemprop="taxonomy">
<h3>Category tags for this page</h3>
<ul property="dcterms:type">
{exp:tagger:tags entry_id="{entry_id}" orderby=”tag_name”}
<li>
{tagger:tag_name}
</li>
{/exp:tagger:tags}
</ul>
</div>
{/if}
{if related_pages != ""}
<div id="related-pages">
{related_entries id="related_pages"}
<h3>{title}</h3>
{body}
{/related_entries}
</div>
{/if}
{if related_posts != ""}
<div id="related-posts">
{related_entries id="related_posts"}
<h3>{title}</h3>
{body}
{/related_entries}
</div>
{/if}
{if related_news != ""}
<div id="related-news">
{related_entries id="related_news"}
<h3>{title}</h3>
{body}
{/related_entries}
</div>
{/if}
</footer>
{/if}
So, I am looking to write conditional code which firstly will only show a footer element if any of taxonomy, related_pages, related_posts or related_news are not empty. Note that related_* are all relationship field IDs.
Within this if statement are nested conditional statements which will only show content blocks if the corresponding IDs are not empty. Unfortunately, it seems that EE doesn't see relationship fields as ever being empty, even when no related content has been selected.
Does anyone know of either what is parsed by the relationship field IDs when no content has been selected, or another workaround to handle what I am trying to do in this code?

Bit long winded, but...
{if "{taxonomy}" != "" OR
"{related_entries id="related_pages"}{entry_id}{/related_entries}" != "" OR
"{related_entries id="related_posts"}{entry_id}{/related_entries}" != "" OR
"{related_entries id="related_news"}{entry_id}{/related_entries}" != ""}
...
{if "{related_entries id="related_pages"}{entry_id}{/related_entries}" != ""}
...
{if "{related_entries id="related_posts"}{entry_id}{/related_entries}" != ""}
...
{if "{related_entries id="related_news"}{entry_id}{/related_entries}" != ""}
...
If your budget can stretch to it the Playa add-on is the King of relationships and makes working with relationships a breeze.

Kudos to Peter Lewis for putting me on the right lines with this. Note that when you use double quotes around IDs, it appears you have to add them around each reference or else an exception is thrown. Also, the limit attribute or count isn't available on related_entries but can be handled with a custom PHP count, as shown in the linked forum thread.
Here is the adapted template code that works:
{if "{taxonomy}" != "" OR
"{related_entries id="related_pages"}{entry_id}{/related_entries}" != "" OR
"{related_entries id="related_posts"}{entry_id}{/related_entries}" != "" OR
"{related_entries id="related_news"}{entry_id}{/related_entries}" != ""}
...
{if taxonomy != ""}
...
{if "{related_entries id="related_pages"}{entry_id}{/related_entries}" != ""}
...
{if "{related_entries id="related_posts"}{entry_id}{/related_entries}" != ""}
...
{if "{related_entries id="related_news"}{entry_id}{/related_entries}" != ""}
...

Related

Convert form select box from .pug to .ejs

I'm trying to convert the below from pug to ejs. It's a select box of authors (from an associated collection) in a form to add a book to the db. It throws error "Cannot read property '_id' of undefined" pointing to the first option element when I add a new book (but I can update an existing book for some reason). And in the pug version it doesn't throw this error. Is my conversion right?
select#author.form-control(type='select', placeholder='Select author' name='author' required='true' )
- authors.sort(function(a, b) {let textA = a.family_name.toUpperCase(); let textB = b.family_name.toUpperCase(); return (textA < textB) ? -1 : (textA > textB) ? 1 : 0;});
for author in authors
if book
option(value=author._id selected=(author._id.toString()==book.author._id.toString() ? 'selected' : false) ) #{author.name}
else
option(value=author._id) #{author.name}
My conversion:
<select class="form-control" id="author" type="select" placeholder="Select author" name="author" required="true">
<% authors.sort(function(a, b) {let textA = a.family_name.toUpperCase(); let textB = b.family_name.toUpperCase(); return (textA < textB) ? -1 : (textA > textB) ? 1 : 0;}); %>
<% authors.forEach(function(author) { %>
<% if(typeof book !== 'undefined') { %>
<option value="<%= author._id %>" selected=<%= (author._id.toString() == book.author._id.toString()) ? 'selected' : 'false' %>><%= author.name %></option>
<% } else { %>
<option value="<% author._id %>"><%= author.name %></option>
<% } %>
<% }) %>
</select>
The conversion is right. Just a little mistake here <%= instead of <%
<option value="<%= author._id %>"><%= author.name %></option>
For any reason book.author is not present. Pug is catching undefined variables and continues rendering while ejs doesn't. So there is something wrong in your data.
Modify this line to prevent the error <% if(typeof book !== 'undefined' && 'author' in book) { %>
<select class="form-control" id="author" type="select" placeholder="Select author" name="author" required="true">
<% authors.sort(function(a, b) {let textA = a.family_name.toUpperCase(); let textB = b.family_name.toUpperCase(); return (textA < textB) ? -1 : (textA > textB) ? 1 : 0;}); %>
<% authors.forEach(function(author) { %>
<% if(typeof book !== 'undefined' && 'author' in book) { %>
<option value="<%= author._id %>" selected=<%= (author._id.toString() == book.author._id.toString()) ? 'selected' : 'false' %>><%= author.name %></option>
<% } else { %>
<option value="<%= author._id %>"><%= author.name %></option>
<% } %>
<% }) %>
</select>

WATIR : how to set a checkbox inside a label

How can I check that checkbox using WATIR
<label title="Active-DC Cloud Management" class="custom-checkbox ng-scope folderSelector">
<span class="customCheckBox icn" ng-disabled="cDisabled">
<input class="ng-pristine ng-valid" ng-model="model" ng-change="changeCallback({$event:$event})" ng-disabled="cDisabled" type="checkbox">
</span> Active-DC Cloud Management<!-- ngIf: cFoldertype == 'ASP' || cFoldertype == 'VCE' || cFoldertype == 'CPL' -->
</label>
I have tried using the following but that doesn't work
#browser.label(:text,'Active-DC Cloud Management').parent.click
Here is more of the HTMl code
<li class="ng-scope" ng-repeat="subfolder in subfolder.subFolders" ng-class="{expandButton:subfolder.hasSubFolders,plus:subfolder.hasSubFolders, disabled:subfolder.folderAccess == 'NONE', selected:selectedFolderIdsArray.indexOf(subfolder.folderId) !== -1}" id="1001665955" ftpath="HOME\Order_12329753" ftname="Order_12329753" ftlevel="2" fttype="ORDER" ftaccess="VIEW">
<a name="&lpos=my : 263" href="javascript:void(0)" ng-click="toggleSelectFolder(subfolder.folderId,subfolder.fullFolderPath)" style="padding-left: 28px" data-this-tree="thisTree" complete-folder-stack="completeFolderStack" folder-data-ftype="subfolder.folderType">
<span class="expandCollapseIcon ng-hide" style="left: 15px" ng-show="subfolder.hasSubFolders" ng-click="expander($event,subfolder.folderAccess); ajaxLoad($event,subfolder)"> </span>
<label class="custom-checkbox ng-scope folderSelector">
<span class="customCheckBox icn" ng-disabled="cDisabled">
<input class="ng-valid ng-dirty" ng-model="model" ng-change="changeCallback({$event:$event})" ng-disabled="cDisabled" type="checkbox"></span>Order_12329753<!-- ngIf: cFoldertype == 'ASP' || cFoldertype == 'VCE' || cFoldertype == 'CPL' --></label></a>
<ul class="subfolder"><!-- ngRepeat: subfolder in subfolder.subFolders --></ul></li>
OK i figured this part out it seems like the div that contains all this code is set to be disabled (not invisible) so because of that I can not use the regular functions associated with the checkbox element but I can use the fire_event method of the browser to click on the checkbox b.input(:xpath,"//label[#title='Active-DC Cloud Management']/span/input").fire_event :click

Finding Current Page in SailsJS

Does anyone know of a prettier way to output a class name to a list element (in this case) using EJS?
<% var active = "active"; %>
<div class="header">
<ul class="nav nav-pills pull-right">
<li class="<% if(req.path == '/user') { %><%= active %><% } %>">Users</li>
<li class="<% if(req.path == '/about') { %><%= active %><% } %>">About</li>
<li class="<% if(req.path == '/contact') { %><%= active %><% } %>">Contact</li>
</ul>
<h3 class="text-muted">Sails Tutorial App</h3>
</div></li>
You can do it like this :)
<li class="<%= (req.path == '/user') ? 'active' : '' %>">Users</li>
It's a little bit prettier I guess...

ExpressionEngine: Multiple channels issue with custom URL's

On this page:
http://build.jhousemedia3.com/pleasanton/shop/district-profile/stoneridge-shopping-center/
The URL is formatted like so
http://build.jhousemedia3.com/pleasanton/[channel]/[template]/[query parameter]
I'm running an exp:channel:entries query using the last segment of the URL (segment_4)
What's happening is that when I run it from this URL I can't pull in data from any other channel except the specific shopping districts channel. If I were to change that last segment to /?id=28 (or something similar) I can pull data from multiple channels.
Any ideas?
Code for pulling the profile of a shopping district based on the URL:
{exp:channel:entries url_title="{segment_4}" limit="1" channel="shopping_districts"}
<h2 class="upper"><span class="greenlight">{title}</span></h2>
{if center_website}
<div class="greyroundbox right"><a href="{center_website}" class="external-link" target='_blank'>Visit the Website</a></div>
{/if}
<p>{shopping_center_description}</p>
<div class="clear"></div>
{/exp:channel:entries}
Code for pulling in any business data
{exp:channel:entries channel="businesses"}
<li class="{switch='first|'}">
<p>
{business_name}
{categories_shopping}<br />
{if phone}
<strong>Phone</strong>: {phone}<br />
{/if}
<strong>Address</strong>: {address_1}<br />
{if address_2}
{address_2}<br />
{/if}
{city}, {state}, {zip}<br />
{if website}
<em>{website}</em>
{/if}
</p>
</li>
{/exp:channel:entries}
Maybe obvious, but have you added dynamic="no" to your other loop?
{exp:channel:entries channel="businesses" dynamic="no"}

ExpressionEngine SafeCracker Form Does Not Submit and Simply Refreshes Page

I have the following contact form, but it does not seem to be submitting when I have completed all of the fields as required. The page just refreshes to show the same form with the data filled in.
{exp:safecracker channel="contact_us" id="form-contact" return="contact-us/thanks" datepicker="no" error_handling="inline" include_jquery="no" rules:cf_contact_us_email="valid_email"}
<fieldset>
<legend>Your contact details</legend>
<ul>
<li><label>{label:cf_contact_us_title}</label>{field:cf_contact_us_title}{if required} *{/if}</li>
{if error:cf_contact_us_title}<li class="error">{error:cf_contact_us_title}</li>{/if}
<li><label>{label:cf_contact_us_name}</label>{field:cf_contact_us_name}{if required} *{/if}</li>
{if error:cf_contact_us_name}<li class="error">{error:cf_contact_us_name}</li>{/if}
<li><label>{label:cf_contact_us_address}</label>{field:cf_contact_us_address}{if required} *{/if}</li>
{if error:cf_contact_us_address}<li class="error">{error:cf_contact_us_address}</li>{/if}
<li><label>{label:cf_contact_us_towncity}</label>{field:cf_contact_us_towncity}{if required} *{/if}</li>
{if error:cf_contact_us_towncity}<li class="error">{error:cf_contact_us_towncity}</li>{/if}
<li><label>{label:cf_contact_us_postcode}</label>{field:cf_contact_us_postcode}{if required} *{/if}</li>
{if error:cf_contact_us_postcode}<li class="error">{error:cf_contact_us_postcode}</li>{/if}
<li><label>{label:cf_contact_us_telephone}</label>{field:cf_contact_us_telephone}{if required} *{/if}</li>
{if error:cf_contact_us_telephone}<li class="error">{error:cf_contact_us_telephone}</li>{/if}
<li><label>{label:cf_contact_us_email}</label>{field:cf_contact_us_email}{if required} *{/if}</li>
{if error:cf_contact_us_email}<li class="error">{error:cf_contact_us_email}</li>{/if}
<li class="inset"><label>{label:cf_contact_us_method}</label></li>
<li>{field:cf_contact_us_method}{if required} *{/if}<br>{error:cf_contact_us_method}</li>
{if error:cf_contact_us_method}<li class="error">{error:cf_contact_us_method}</li>{/if}
<li><label>{label:cf_contact_us_enquiry}</label>{field:cf_contact_us_enquiry}{if required} *{/if}</li>
{if error:cf_contact_us_enquiry}<li class="error">{error:cf_contact_us_enquiry}</li>{/if}
<li class="checkbox-first">{field:cf_contact_us_terms} Terms and Conditions{if required} *{/if}</li>
{if error:cf_contact_us_terms}<li class="error">{error:cf_contact_us_terms}</li>{/if}
<span class="clearfix"></span>
<li class="form-button"><input type="submit" class="submit rounded" name="send" value="Send" /></li>
</ul>
</fieldset>
{/exp:safecracker}
I wondered if anyone might be able to help me figure this out. It’s likely something incredibly obvious.
Try removing the error_handling="inline" parameter, which will allow you to see the actual error message(s) SafeCracker is presenting to you thru the User Message Templates.
In looking over your code, your SafeCracker form seems to be missing the Title {title} field, which I believe is required by SafeCracker — either thru a hidden input or supplied by the user.
To troubleshoot your SafeCracker form:
Remove the Error Handling Parameter
Include the Entry Title Field {title}
Doing this will allow you to:
See the Full Error Message
Submit the Entry to ExpressionEngine
Once you have everything working, you can change the error handling parameter back to inline.

Resources