TL;DR: Microdata forces you to use the itemprop on the same element as the itemtype that is this itemprops vaule. How do you deal with this, if you want to break up your template into partials? The element may only appear in one of the two places, either in the containing template or the included partial, both of which does not really work well.
I am using Rails with haml, but I guess my question applies to any templating engine, where you can split up your template into smaller partials. I am heavily making use of partials, that means my templates are usually no longer than 10 lines of code. But fitting microdata into these seems overly complicated, so how are you supposed to use microdata properly with partials?
Take this example:
#app/views/article/show.html.haml
%p Hey, Welcome! Read This wonderful article:
= render @article
#app/views/articles/_article.html.haml
%div[ article ]
%h1= @article.title
%p= @article.description
%div= render @article.video
#app/views/videos/_video.html.haml
%div[ video ]
%h2= video.file_name
%video{ src: video.url }
And now with microdata:
#app/views/articles/_article.html.haml
%div[ article ]{ itemscope: true, itemtype: 'http://schema.org/Article' }
%h1{ itemprop: 'name' }= @article.title
%p{ itemprop: 'description' }= @article.description
%div{ itemprop: 'video' }= render @article.video
And then what? I have to add the VideoObject
itemtype on the same div, that has the itemprop: 'video'
because, that's how microdata works. So:
#app/views/articles/_article.html.haml
%div{ itemprop: 'video', itemscope: true, itemtype: 'http://schema.org/VideoObject' }= render @article.video
But then I can't use that same itemtype again in the video partial. This would now be invalid:
#app/views/videos/_video.html.haml
%div[ video, itemscope: true, itemtype: 'http://schema.org/VideoObject' ]
But the itemtype belongs to the video. I don't want to repeat it in every single container-element. I want to be able to use the video partial everywhere else and still have it declared as a video with microdata. So the whole thing has to move out of the article partial and into the vido partial like this:
#app/views/articles/_article.html.haml
%div= render @article.video
#app/views/videos/_video.html.haml
%div[ video ]{ itemprop: 'video', itemscope: true, itemtype: 'http://schema.org/VideoObject' }
Again, the itemprop has to be on the same element as the video itemtype . But why should the video partial care/know how the itemprop is called that it is the value of?
The only solution I have, is to pass the itemprop into the partial. This also means, we have to declare a default itemprop in case none is passed. So we end up with this:
#app/views/articles/_article.html.haml
%div= render @article.video, itemprop: 'video'
#app/views/videos/_video.html.haml
itemprop ||= nil
%div[ video ]{ itemprop: itemprop, itemscope: true, itemtype: 'http://schema.org/VideoObject' }
That seems overly complicated. Also I find it quite confusing to pass the name of an the itemprop into the partial, so the partial knows what the itemprop is called that it is the value of. How weird is that? Nowhere else in programming have I encountered objects that needed to know the name of the thing that points to them.
So is there a better established way to do this? Or is that just how it is and I should not not be so whiny about it? ☺
@article.prop.name
, and@article.prop.url
(or schema) for example – Mohammad AbuShady