tag:help-archives.hannonhill.com,2010-02-09:/discussions/how-do-i/22051-determine-asset-depth-in-a-formatCascade CMS: Discussion 2016-06-06T12:02:33Ztag:help-archives.hannonhill.com,2010-02-09:Comment/399058002016-05-17T19:52:30Z2016-05-17T19:52:30ZDetermine asset depth in a format?<div><p>Hi Rob,</p>
<p>I believe the best way to accomplish this would be to look at
its path and count the number of <code>/</code> characters.</p>
<p>Paths always begin with <code>/</code>, so you would need to
determine if you want depth of one to mean root level, or if you
would want to subtract one and use 0 to indicate root level.</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/399058002016-05-18T14:49:34Z2016-05-18T14:49:34ZDetermine asset depth in a format?<div><p>Hi Ryan,</p>
<p>Thank you for answering my question. That makes sense. Do you
have a code snippet in either XSL or Velocity that does something
like that? Even something similar would help, as I'm not sure where
to start counting occurrences of a character within a string.</p>
<p>Thank you!</p></div>Rob Knighttag:help-archives.hannonhill.com,2010-02-09:Comment/399058002016-05-18T15:55:23Z2016-05-18T15:55:23ZDetermine asset depth in a format?<div><p>Hi Rob,</p>
<p>Velocity would be the easier option. Consider the following
snippet to help get you started:</p>
<pre>
<code>#foreach ($asset in $assets)
#set ($path = $asset.getChild("path").value)
#set ($depth = $path.split("/").size())
#end</code>
</pre>
<p>To summarize: the <code>$depth</code> variable will be value
<strong>1</strong> if the asset is within the base folder, because
it's path looks like <code>/about</code>. The variable would be
<strong>2</strong> if the asset is one level under the base folder,
because it's path looks like <code>/folder/about</code>. And so
on.</p>
<p>As I mentioned, you would need to determine how you want to
denote "root level," do you want a value of <strong>1</strong>, or
a value of <strong>0</strong>. If you want to go with
<strong>0</strong>, you would need to tweak the format slightly to
subtract one from the depth:</p>
<pre>
<code>#set ($depth = $_MathTool.sub($path.split("/").size(), 1))</code>
</pre>
<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/399058002016-06-05T05:46:32Z2016-06-05T05:46:32ZDetermine asset depth in a format?<div><p>This was extremely helpful. Thank you, Ryan.</p></div>Rob Knighttag:help-archives.hannonhill.com,2010-02-09:Comment/399058002016-06-06T12:02:31Z2016-06-06T12:02:31ZDetermine asset depth in a format?<div><p>Not a problem at all, Rob. I am glad to hear my suggestion
helped out.</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 Griffith