enkelmedia / Umbraco-SeoVisualizer

SEO Visualizer property editor for Umbraco
https://marketplace.umbraco.com/package/umbracoseovisualizer
MIT License
9 stars 11 forks source link

Questions on its usage #2

Closed akeilox closed 9 years ago

akeilox commented 10 years ago

I came across this and was excited about the use-case for editors to preview and edit SEO title and description with preview. However when i try to use the code as specified (the second one), it throws error as below. This code is on a template (umbraco 7.1.6); The property is named seo in the assigned page.

Compiler Error Message: CS1061: 'object' does not contain a definition for 'Title' and no extension method 'Title' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

Source Error: Line 28: @{ var seo = this.Model.Content.GetPropertyValue("seo"); } Line 29: Line 30: @seo.Title @seo.Description

enkelmedia commented 10 years ago

Hi!

Thank you!

Hmm. Could it be a typo in the docs?

Try this: var seo = this.Model.Content.GetPropertyValue("seo");

CodeAbuser commented 9 years ago

I'm getting the same error. when i just output @seo i see { "title": "SEO title", "description": "this is the description" } on the page, but it looks like @seo.Title throws an error. is there a using statement or something that i'm missing?

enkelmedia commented 9 years ago

Hi!

Try this.Model.Content.GetPropertyValue("seo").Description

Does that work?

CodeAbuser commented 9 years ago

using that gives me this error:

'object' does not contain a definition for 'Description' and no extension method 'Description' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

CodeAbuser commented 9 years ago

if anybody else tries to use this and has the same issue, here's the solution:

add using statements to your view:

@using Umbraco.Web @using Newtonsoft.Json.Linq

then parse the object to JObject:

var seo = JObject.Parse(this.Model.Content.GetPropertyValue("seo").ToString());

then get the values like this:

@seo.GetValue("title") @seo.GetValue("description")

rossiter10 commented 9 years ago

CodeAbuser's solution works, just make sure to check for empty values first(and remember those using statements!). Here's what I did, but you probably should set the value as a variable first so you don't have to get it twice... if (!String.IsNullOrEmpty(this.Model.Content.GetPropertyValue("seo").ToString())) { var seo = JObject.Parse(this.Model.Content.GetPropertyValue("seo").ToString()); meta name="title" content="@seo.GetValue("title")" meta name="description" content="@seo.GetValue("description")" }

I left off the meta tag brackets so they would show up in the comment

enkelmedia commented 9 years ago

Hi!

Since we added the property value converters you can use it like this:

@(this.Model.Content.GetPropertyValue<SeoValues>("seo").Description)

or like this

@{ var seo = this.Model.Content.GetPropertyValue<SeoValues>("seo"); }

@seo.Description @seo.Title

The <SeoValues>-part of the lines where stripped from documentation (readme.md) by github so I hade to change to < and > in the markdown.

Sorry about this simple mistake. Hope this helps!

CodeAbuser commented 9 years ago

does this require downloading a new version or can i use this now? What using statement do i need to be able to resolve the SeoValues object?

enkelmedia commented 9 years ago

You should be able to use the current version. Just include the namespace "SeoVisualizer"

CodeAbuser commented 9 years ago

@using SeoVisualizer;

That gives me an error. namespace not found

enkelmedia commented 9 years ago

Strange - do you have the dll in the bin-folder? If not - download the latest version from our.umbraco.org and install it again.

CodeAbuser commented 9 years ago

i did not have the dll. i upgraded to the latest version and the dll is there now and your example works. thanks!