-
Notifications
You must be signed in to change notification settings - Fork 2.5k
HtmlTag helper #6709
HtmlTag helper #6709
Conversation
…some custom attributes can be added dynamically.
* Retrieve object instance; optionally add attributes. | ||
* | ||
* @param array $attribs | ||
* @return \Zend\View\Helper\HtmlTag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@return self
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously there is no consensus inside ZF2 codebase when it comes to that @return
annotation in case of some fluent-interface method which returns self reference. Somewhere you will see self, while on some other place name of the class or a fully qualified class name, like in case of this class. I prefer that variant, so I would rather leave it as is. At least until some coding standard for this purpose is defined. :)
I'm in doubt whether this is an appropriate view helper name. It is kind of undetermined, neutral. And it can also be confused with existing Html* helpers, like HtmlObject, HtmlPage, HtmlFlash, etc. Any better ideas? |
…Also added new test case for that method.
Why do I need to know the correct URL for XHTML, if I want to use the helper? Please compare with the Otherwise, the helper would be useless. (imo) |
Ok, good point. I will try to make same changes in that direction, but I'd rather limit those new "helping" abilities of this helper to standard, default attributes, like |
With that example, how do you add multiple namespaces? |
I suppose that you are referring example from the initial description, so appropriate helper invocation might look like: $this->html()->setAttributes(array(
'xmlns' => 'http://www.w3.org/1999/xhtml',
'xmlns:og' => 'http://ogp.me/ns#'
)); |
And what was this for in the example?
|
Open Graph protocol: http://ogp.me/. It is recommended that |
By the way, I have created a ZF2 module which facilitates OG integration (https://github.com/nikolaposa/ZfOpenGraph), which internally relies on the HeadMeta helper. This proposal was created exactly because I lacked ability to dynamically attach necessary OG-specific attribute on the html tag itself, from the context of a OpenGraph view helper that I created. |
…r the html tag based on currently set doctype.
@froschdesign What do you think about that approach with |
Please choose a better name for |
Ok, thanks for the feedback, it makes sense. |
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2015 ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I really have to modify that? :) I also have some other PRs planned for 2.4.0 within which new classes are added, like this one: #6058, and I haven't got such remark from a code reviewer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it will be done after merge. I don't feel like burdening existing PRs with these changes is needed at all ;-)
Update copyright in new files introduced in #6709
Merged to develop for release in 2.4. |
…eature/html_tag_helper HtmlTag helper
Update copyright in new files introduced in zendframework/zendframework#6709
New view helper used for rendering
<html>
tag of a web page, to which some custom attributes can be added dynamically.Intent
Idea is to have ability to dynamically attach some attributes to the opening HTML tag in a layout. For example:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#">
Usage
Rendering tag in a layout:
Adding attributes:
There is also option to automatically pre-set appropriate namespace attributes, based on currently set DOCTYPE (
Doctype
helper):