Need to put this into Umbraco V5 using Razor Macros: (the var 'source' is my homepage ID, so I've added content on my homepage and then want to put this macro anywhere on the site and it will pull the content from the homepage like recursive.)
I believe you can get the root, or 'home' node, as it were, by doing,
var root = DynamicModel.AncestorsOrSelf.Last();
then you can access the properties of the document type such that,
@Html.Raw(root.fieldName)
However, I notice your XSLT is doing a for-each, and I've no idea why since you mentioned you've added content to your home page. But either way, once you get the home page as described above there's nothing really stopping you. You can iterate with a foreach loop over the Ancestors, Children, or using the dynamics, a pluralisation of the Document Types you're looking for. So something like,
foreach (var child in root.myDocumentTypes) { @Html.Raw(child.fieldName) }
Of course you may need to be precise about the node retrieved by means of an identifier. Reasonable. So you can using the Model (as opposed the DynamicModel, which I don't think exposes this functionality),
var explicitNode = Model.NodeById(identifer);
Then I think you need to go about getting at the document type properties in a slightly more verbose way (using indexers like a viewbag).
@Grant Woops, I read too fast and did not see the V5 mention.
Strange that is is not compatible, I guess there is a good reason why they changed the DynamicModel in V5... Anyway, in that case it is indeed something like you mention in your post.
How would you do this? (Convert XSLT to Razor)
Need to put this into Umbraco V5 using Razor Macros:
(the var 'source' is my homepage ID, so I've added content on my homepage and then want to put this macro anywhere on the site and it will pull the content from the homepage like recursive.)
<xsl:variable name="source" select="1050"/>
<!-- start writing XSLT -->
<xsl:for-each select="umbraco.library:GetXmlNodeById($source)/ancestor-or-self::* [@isDoc]">
<xsl:value-of select="fieldName" disable-output-escaping="yes" />
</xsl:for-each>
I believe you can get the root, or 'home' node, as it were, by doing,
then you can access the properties of the document type such that,
However, I notice your XSLT is doing a for-each, and I've no idea why since you mentioned you've added content to your home page. But either way, once you get the home page as described above there's nothing really stopping you. You can iterate with a foreach loop over the Ancestors, Children, or using the dynamics, a pluralisation of the Document Types you're looking for. So something like,
Of course you may need to be precise about the node retrieved by means of an identifier. Reasonable. So you can using the Model (as opposed the DynamicModel, which I don't think exposes this functionality),
Then I think you need to go about getting at the document type properties in a slightly more verbose way (using indexers like a viewbag).
Am I doing this right?
I'm trying to pull this field from the home page and display it on a text page with a macro. It's not showing anything....
Hi Jim,
I think you should use AncestorsOrSelf() (as a function, not as a property)
I'm not sure, but could it be that you have to use First() instead of Last()?
Also, I think an easier way of getting to the root node is by using one of the AncestorsOrSelf overwrites:
- with specification of the nodetypeAlias => e.g. AncestorsOrSelf("MyHomePageNodeTypeAlias")
- with the level => e.g. AncestorsOrSelf(1) (or 0, or whatever the level of your homepage is)
Here is a nice razor resource if you have not found it yet : the razor dynamicmodel cheat sheet http://our.umbraco.org/projects/developer-tools/razor-dynamicnode-cheat-sheet
Hope this helps :-)
Cheers,
Michael.
Michael, AncestorsOrSelf is exposes as a property on the DynamicModel of v5.
This also means we don't have the queryability on that, and would need to do something like:
In fact, through my playings about with v5 so far, much of that PDF document is out of date.
Jim, so to answer your question, using the above you could try,
@Grant Woops, I read too fast and did not see the V5 mention.
Strange that is is not compatible, I guess there is a good reason why they changed the DynamicModel in V5... Anyway, in that case it is indeed something like you mention in your post.
Cheers,
Michael.
is working on a reply...