Developer forum

Forum » CMS - Standard features » W3C HTML Validation

W3C HTML Validation

Victor Jonsson
Reply

Good day.

I have two points where It seems DW fails to escape/encode characters to html entities. That in turn makes the resulting html invalid. Strictly speaking :)

  1. Urls have & instead of &
  2. Product name that has a double quote (").
    When using the product name in an alt attribute causes the attribute to be closed too soon.

(Now, there might be more places than these two mentioned above. I don't know)

I'm wondering If there's a workaround? Maybe I'm not using the right tags?

Regards, Victor


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Victor

 

On the website properties you can choose html version - and that control some of the output among them the & in URLs.. HTML 4 and HTML 5 does not require & in links - only xhtml 1, and that was stupid so they changed it back with HTML 5.

 

In these modern days you should use the HTML 5 doctype and set the html type on the website properties accordingly. That will give you the best rendering in most browsers. You do not need to use HTML 5 tags, but just the doctype.

 

Product names are not meant to be used for attributes - and if you type in double quotes in the name it is because you want it.

 

But you can use a template extension method to remove stuff like that. see:

http://templates.dynamicweb-cms.com/TemplateTags/Dynamicweb-template-tags/General-tags/Encoding-extensions.aspx

 

So you could do like <tag attribute="<!--@ Product.Name.UrlEncoded()-->"> and that would work

 
Victor Jonsson
Reply

Hi Nicolai and thank you for your response.

I had not noticed these template extensions. They'll be handy in the future.

Despite the site using HTML5, the tag <!--@Ecom:VariantCombination.LinkGroup.Clean--> outputs & instead of &amp;

I tried using the .UrlEncoded() extension and that took care of the validation but the link doesn't work anymore. :)

Working, non-validating url:

Default.aspx?ID=107&amp;GroupID=GROUP7&amp;ProductID=PROD142&amp;VariantID=VO12

UrlEncoded (returns Page not found):

Default.aspx%3fID%3d107%26GroupID%3dGROUP7%26ProductID%3dPROD142%26VariantID%3dVO12

Also, unfortunately .UrlEncoded() result is pretty unusable as a title or alt tag. Looks like jibberish :)

But what about the .HtmlEncoded() extension? It doesn't seem to do anything in my example of the Product.Name. I would have guessed that it would encode this: Schwinn Tiger 12" Kid’s Bike to Schwinn Tiger 12&quot Kid’s Bike.

As per this online html encoder

Thanks again for taking the time to help!

Regards, Victor.

 

 
Nicolai Høeg Pedersen
Reply

Hi Victor

 

You need to set the website html type to Html5 AND change your "doctype" of your template to HTML 5 also.

Try read this post:

http://www.w3schools.com/tags/tag_doctype.asp

 

The HtmlEncoded() extension does exactly what the online HTML encoder. How does your full tag look like? I think you might use it wrong.

 

BR Nicolai

 

 

 
Victor Jonsson
Reply

Strange, htmlencode works now.

I'm was and still am using <!doctype html> along with HTML5 selected in DW.

I just tried again using htmlencode and now it works like i thought it would. 

Here's an example: <!--@Ecom:Product.Name.HtmlEncoded()-->

I must have done something wrong last time.

I'm still having problems with validation. The frontpage now validates with the variant loop while another product category page doesn't. Why would the validator look past the & on one page and not another. Hmm. There must be something different.

I'll figure it out.  Thanks for the help Nicolai.

Regards, Victor

 

You must be logged in to post in the forum