It appears there is no uComponents namespace in umbraco 6, or I don't know how to access it, so I'm not sure how to go about this exactly. Thanks for any guidance
If you did specifically want to use uQuery then it now resides in the umbraco namespace rather than uComponents, there is full documentation for uQuery available here
well, i feel sheepish. I did not have ucomponents installed. once I added that my code worked as intended. Thank you for the tips, everybody. I will probably take a look at the documentation for uQuery and try to use it without uComponents if I don't need it for this.
If you do use uQuery, make sure you use it from the umbraco namespace rather than uComponents as that version is maintained only for legacy and isn't fully Umbraco v6 compatible.
I marked your snippet as the answer because it's pretty much what i used. Here's what I ended up doing for a redirect to an external URL
@{
var url = "";
if (Model.Content.HasValue("customRedirectUrl")){
url = Convert.ToString(Model.Content.GetPropertyValue("customRedirectUrl"));}
if (!(string.IsNullOrEmpty(url))){
Response.Redirect(url);}
}
I also uninstalled uComponents. it broke my back office - I couldn't edit document type properties. One other question though, is there any built in document property I could set on a document node to do an internal redirect with a querystring? I saw the UmbracoInternalRedirectId property which is pretty close to what I want, I just want to set a querystring as well. My snippet above accomplishes that, just wondering if there was a better way.
I have another site now with masterpages. How would I accomplish this in a MasterPage? Using the same code doesn't throw an error, but Model.Content.GetPropertyValue
a-ha! I just got it. I was missing the @inherits umbraco.web.macros.partialviewmacropage line. Here is the working cshtml razor macro in case it would help anybody else
@using Umbraco
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
//custom redirect url property to allow redirect to external URLs or URL with query string
Response.Write(Model.Content.GetPropertyValue<string>("customRedirectUrl"));
var url = "";
if (Model.Content.HasValue("customRedirectUrl")){
url = Model.Content.GetPropertyValue<string>("customRedirectUrl");}
if (!(string.IsNullOrEmpty(url))){
Response.Redirect(url);}
}
getting node properties in umbraco 6
I'm attemptint to retrieve node properties in a razor template in umbraco 6 and having some trouble. I'd like to get properties similar to how they fetch the title in this example http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/uquery-dynamic-title
It appears there is no uComponents namespace in umbraco 6, or I don't know how to access it, so I'm not sure how to go about this exactly. Thanks for any guidance
Hi Steve,
First question is, are you using .cshtml Mvc templates or .master MasterPage templates?
Thanks,
Jeavon
cshtml mvc
Also...do you have uComponents installed ?
http://ucomponents.org/
Ok, so then you should do something like this for a textbox property with an alias of "pageTitleH1"
Lots of useful documentation available below:
For different property editors: http://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/
For general MVC querying: http://our.umbraco.org/documentation/Reference/Mvc/querying
If you did specifically want to use uQuery then it now resides in the umbraco namespace rather than uComponents, there is full documentation for uQuery available here
well, i feel sheepish. I did not have ucomponents installed. once I added that my code worked as intended. Thank you for the tips, everybody. I will probably take a look at the documentation for uQuery and try to use it without uComponents if I don't need it for this.
If you do use uQuery, make sure you use it from the umbraco namespace rather than uComponents as that version is maintained only for legacy and isn't fully Umbraco v6 compatible.
I marked your snippet as the answer because it's pretty much what i used. Here's what I ended up doing for a redirect to an external URL
I also uninstalled uComponents. it broke my back office - I couldn't edit document type properties. One other question though, is there any built in document property I could set on a document node to do an internal redirect with a querystring? I saw the UmbracoInternalRedirectId property which is pretty close to what I want, I just want to set a querystring as well. My snippet above accomplishes that, just wondering if there was a better way.
Nope, the only way I can think of to include the querystring in the redirect is pretty much exactly what you have done.
I think I would do url = Model.Content.GetPropertyValue<string>("customRedirectUrl") instead of using the Convert.ToString but doesn't matter :-)
I have another site now with masterpages. How would I accomplish this in a MasterPage? Using the same code doesn't throw an error, but Model.Content.GetPropertyValue
Hi Steve,
When you say masterpages, are you using a Razor macro or a Razor embedded in the .master page or something else?
Thanks,
Jeavon
I tried both ways actually
Ok, can you post your whole .cshtml file Razor macro code?
Jeavon, to clarify, I tried using a cshtml razor macro and embedding razor in the .master page. Thanks for the reply.
a-ha! I just got it. I was missing the @inherits umbraco.web.macros.partialviewmacropage line. Here is the working cshtml razor macro in case it would help anybody else
Great, I see you are actually using a Partial View Macro rather than a Razor Macro, slightly confusing names I guess.....
is working on a reply...