tag:help-archives.hannonhill.com,2010-02-09:/discussions/velocity-formats/7854-creating-format-that-looks-for-blocks-with-a-certain-data-fieldCascade CMS: Discussion 2013-10-16T15:26:37Ztag:help-archives.hannonhill.com,2010-02-09:Comment/294281212013-10-16T13:08:06Z2013-10-16T13:08:06ZCreating format that looks for blocks with a certain data field<div><p>Hi Graham,</p>
<p>It sounds as though either <strong>$contentRoot</strong> is not
being set, or the XPath is not correct. Can you confirm you are
applying an Index Block with this Format? If not, then
<strong>$contentRoot</strong> will not be set.</p>
<p>Also, it looks like your <code>#foreach</code> may need to be
tweaked slightly based on the XPath you are using. Try the
following and let me know if you continue to see the error:</p>
<pre>
<code>#set ($scholarships = $_XPathTool.selectNodes($contentRoot, "//system-block/system-data-structure[schol-major='Nursing']"))
<div class="body_text">
#foreach ($scholarship in $scholarships)
#set ( $name = $scholarship.getChild("schol-name") )
#set ( $type = $scholarship.getChild("schol-type") )
#set ( $value = $scholarship.getChild("schol-value") )
#set ( $major = $scholarship.getChild("schol-major") )
<p>
$_SerializerTool.serialize($name, true), $_SerializerTool.serialize($type, true) $_SerializerTool.serialize($value, true) $_SerializerTool.serialize($major, true)
</p>
#end
</div></code>
</pre>
<p>Note: you are already grabbing the
<strong>system-data-structure</strong> elements when you call
selectNodes, so you do not need <code>#set ( $scholData =
$scholarship.getChild("system-data-structure") )</code></p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/294281212013-10-16T13:24:21Z2013-10-16T13:24:21ZCreating format that looks for blocks with a certain data field<div><p>That worked! I did realize that when I was hitting test format,
I wasn't giving it anything to test to. Yeahh, that's my bad. But
even when I did, my format didn't work and yours did.</p>
<p>I am thinking I am going to have to tweak the DD for this to
make a check box or something to set what the major is. Right now,
it's just a text box that he types in. That way it is consistent
with naming. If there are multiple things checked - Nursing,
Computer Science, Art - could I modify the initial variable to look
for "Art" then a format to look for "Computer Science"?</p>
<p>Also, is this the best place for it? Or should it be in the
metadata? That way he can keep editing the same way he has been
just add the tag for what department it is.</p></div>Graham Lewistag:help-archives.hannonhill.com,2010-02-09:Comment/294281212013-10-16T13:49:58Z2013-10-16T13:49:58ZCreating format that looks for blocks with a certain data field<div><p>Hi Graham,</p>
<p>I am glad to hear that did the trick, you were very close as
usual.</p>
<blockquote>
<p>Also, is this the best place for it? Or should it be in the
metadata? That way he can keep editing the same way he has been
just add the tag for what department it is.</p>
</blockquote>
<p>Typically I see this as a multi-select within the Metadata so
you can re-use the Metadata Set and not have to maintain multiple
select boxes. Within your Format, you would need to match the
current page's "major" with the major(s) for the scholarship.</p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/294281212013-10-16T14:12:48Z2013-10-16T14:12:48ZCreating format that looks for blocks with a certain data field<div><p>I got ya. That makes sense, plus I don't have to edit the Data
Definition itself - I'll try that out. We are wanting to do a lot
more of this type of stuff so we can't have content that is
dynamically made on pages with out editors having to edit it.</p>
<p>Scholarship listings, news, events, etc.</p>
<p>Thanks!</p></div>Graham Lewistag:help-archives.hannonhill.com,2010-02-09:Comment/294281212013-10-16T14:31:47Z2013-10-16T14:31:47ZCreating format that looks for blocks with a certain data field<div><p>This type of setup definitely helps make things more
dynamic.</p>
<p>We have a sample of this in the <strong>example.com</strong>
Site that ships with the default database. Also, I believe <a href=
"https://github.com/hannonhill/Example-Sites/tree/master/Blog">this
sample site</a> has something similar. It may use XSLT, but it will
give you an idea on how to set up your XPath.</p>
<p>I'm going to go ahead and close this discussion, please feel
free to comment or reply to re-open if you have any additional
questions.</p>
<p>Have a great day!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/294281212013-10-16T14:43:18Z2013-10-16T14:43:18ZCreating format that looks for blocks with a certain data field<div><p>thanks! I will check out the example.com site - have a good
one!</p></div>Graham Lewistag:help-archives.hannonhill.com,2010-02-09:Comment/294281212013-10-16T15:26:36Z2013-10-16T15:26:36ZCreating format that looks for blocks with a certain data field<div><p>Not a problem at all, Graham. You have a good one as well.</p></div>Ryan Griffith