i have a problem i can´t seem to get around. I use Razor and embedded content. When i wan´t my embedded content for the current node, i use .XPath("//billeder/data/item") on @Model. But my problem is, that i get all the embedded content nodes, and not only the content from the current node. Why is that, and is there a way to do this?
In XPath, when you use "//" it means look for items from the root, instead of in the current path. However, the "root" of @Model should be the current page and not the whole cache.. Weird, I should test this. For now, you can just use "/billeder/data/item", right? Or @Model.billeder.data.item (I don't know what the embedded content xml output looks like though).
<ul>
@*Show the url's that are selected with the embedded content package.*@
@foreach (dynamic item in Model.projectUrls)
{
<li>
<a href="@item.url" target="_blank">@item.title</a>
</li>
}
</ul>
Wow thanks Jeroen, that was just what i was looking for. I´m quite new to Razor, so thanks alot for the example. Sadly enough, i have allready voted for MVP :-)
@Tony Kiernan Thank you for this hint. So we now need to deal with the @item in your example (and our actual case!) as a DynamicXml now which is being treated and working differently. The InnerText property seems OK if we wanted to deal with a giant flattened string, but we don't, so now the challenge is to find out how to work around this and drill into our tree. (Unforunately, the "Razor Feature Walkthough" has no suitable examples or API published for us to reference, and we are left guessing as to how to query our EmbeddedContent data nodes in a convenient manner.) For example, there is an InnerText, as you showed, but no such InnerXml nor dynamic properties to use instead??
What we are really missing at this point is a "here is how to convert stuff (Razor over EmbeddedContent) that used to work in 4.7.0 to work now in 4.7.1". I've tried probably dozens of different combinations and guessing now at property/method names and now I guess next step is to download Umbraco source and find out what DynamicXml's API is...?
I perhaps should start a new topic for this, since I didn't realize at first this is marked as "solved" already per a five-month old original message...
The XPath method in razor will give you access to the whole cache, so querying from the root (ie //somenode) will query from the root of your site not the current node as you'd expect in XSLT. Removing those preceding slashes fixes this
Razor and embedded content
Hi there,
i have a problem i can´t seem to get around. I use Razor and embedded content. When i wan´t my embedded content for the current node, i use .XPath("//billeder/data/item") on @Model. But my problem is, that i get all the embedded content nodes, and not only the content from the current node. Why is that, and is there a way to do this?
Kind regards
René
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas; color: #b3251e}
In XPath, when you use "//" it means look for items from the root, instead of in the current path. However, the "root" of @Model should be the current page and not the whole cache.. Weird, I should test this. For now, you can just use "/billeder/data/item", right? Or @Model.billeder.data.item (I don't know what the embedded content xml output looks like though).
Thought the same as you Sebastian. But apparently thats not the case. So .XPath("billeder/data/item") works for me now. Thanks for the effort.
/René
Why would you want to use an XPath for this? In Razor you can work much easier with Embedded Content. Here is an example:
Here is the Embedded Content xml:
Here is my Razor code:
Jeroen
Wow thanks Jeroen, that was just what i was looking for. I´m quite new to Razor, so thanks alot for the example. Sadly enough, i have allready voted for MVP :-)
Perfect, just what I was looking for... :)
OK, I followed Joreon's post and had this working. I've updated the site from 4.7.0 to 4.7.1 and it's stopped working
My code:
My XML
Am I missing something?
The dynamic xml has been changed (improved) in 4.7.1. You can read all about it in this blogpost: http://umbraco.com/follow-us/blog-archive/2011/9/15/umbraco-razor-feature-walkthrough%E2%80%93part-6.aspx.
Jeroen
OK, this works
But, surely if I had more than one attribute in there it wouldn't?
Will give that a read
@Tony Kiernan Thank you for this hint. So we now need to deal with the @item in your example (and our actual case!) as a DynamicXml now which is being treated and working differently. The InnerText property seems OK if we wanted to deal with a giant flattened string, but we don't, so now the challenge is to find out how to work around this and drill into our tree. (Unforunately, the "Razor Feature Walkthough" has no suitable examples or API published for us to reference, and we are left guessing as to how to query our EmbeddedContent data nodes in a convenient manner.) For example, there is an InnerText, as you showed, but no such InnerXml nor dynamic properties to use instead??
What we are really missing at this point is a "here is how to convert stuff (Razor over EmbeddedContent) that used to work in 4.7.0 to work now in 4.7.1". I've tried probably dozens of different combinations and guessing now at property/method names and now I guess next step is to download Umbraco source and find out what DynamicXml's API is...?
Thank you for your help!
I perhaps should start a new topic for this, since I didn't realize at first this is marked as "solved" already per a five-month old original message...
this is work for me :
@item.propertyAlias.InnerText.ToString()
The XPath method in razor will give you access to the whole cache, so querying from the root (ie //somenode) will query from the root of your site not the current node as you'd expect in XSLT. Removing those preceding slashes fixes this
how would i go about getting a SPECIFIC node in the embedded content? i am new to razor and still don't quite get it all.
thanks,
is working on a reply...