Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Just wondering.. I had the error in the other post to do with writing out an property from a razor macro.. what is the best way to check for null etc? i.e. what datatype is Model.someproperty by default? i ended up doing:
@if((Model.pageTitle != null && !string.IsNullOrEmpty(Model.pageTitle.ToString())) || (Model.siteName != null && !string.IsNullOrEmpty(Model.siteName.ToString()))) { <title>@Model.siteName</title> }
but surely there's a cleaner way!?
In 4.7.1
@Model.HasValue("pageTitle") or a variety of other approaches :)
Hi Gareth.. so what would i be doing to appropriately check these vars? where useAnalytics is a true false field..
@inherits umbraco.MacroEngines.DynamicNodeContext
@{ var useAnalytics = @Model.AncestorsOrSelf().googleTrackingEnabled; }
if(!string.IsNullOrEmpty(@useAnalytics.ToString()) && @useAnalytics)
{
@{ var googleTrackingAccountID = @Model.AncestorsOrSelf().googleTrackingAccountID; }
@if(!string.IsNullOrEmpty(@googleTrackingAccountID.ToString()))
<script type="text/javascript">
//<![CDATA[
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '@googleTrackingAccountID']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
//]]>
</script>
}
What you're doing is probably the cleanest way in 4.7.0, other than type checking to see if the property type is DynamicNull
4.7.1 improves on this a lot, if you're interested in testing a prerelease version, let me know
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Model.something - something is what datatype?
Just wondering.. I had the error in the other post to do with writing out an property from a razor macro.. what is the best way to check for null etc? i.e. what datatype is Model.someproperty by default? i ended up doing:
@if((Model.pageTitle != null && !string.IsNullOrEmpty(Model.pageTitle.ToString())) || (Model.siteName != null && !string.IsNullOrEmpty(Model.siteName.ToString())))
{
<title>@Model.siteName</title>
}
but surely there's a cleaner way!?
In 4.7.1
@Model.HasValue("pageTitle") or a variety of other approaches :)
Hi Gareth.. so what would i be doing to appropriately check these vars? where useAnalytics is a true false field..
What you're doing is probably the cleanest way in 4.7.0, other than type checking to see if the property type is DynamicNull
4.7.1 improves on this a lot, if you're interested in testing a prerelease version, let me know
is working on a reply...