Hi,
I've implemented Simple HTML DOM for my template engine. Works great!
My template engine uses certain expressions which make the parser fail.
The following case fails:
<form method="post" action="{NodeUrl()}" id="FrontofficeForm{Node.id}" class="FrontofficeForm"{IfTrue( Form.hasUploads, ' enctype="multipart/form-data"' )}>
Directly after class="FrontofficeForm" the expression starts with a curly brace, causing the parser to completely ignore the expression and remove it when innertext() or outertext() is called.
I've added the following hack to make sure the expression is treated as if it's an attribute, replacing line 812 to 820:
// Collect remaining text and restore noise $remainingTextInOpeningTag = $this->restore_noise( $this->copy_until_char_escape( '>' ) ); $lastCharInRemainingText = $remainingTextInOpeningTag[ strlen( $remainingTextInOpeningTag) - 1 ]; if ( $lastCharInRemainingText == '/' ) $remainingTextInOpeningTag = substr( $remainingTextInOpeningTag, 0, strlen( $remainingTextInOpeningTag ) - 1 ); if ( !in_array( trim( $remainingTextInOpeningTag ), array( '', '/' ) ) ) { $node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_NO; $node->attr[ $remainingTextInOpeningTag ] = true; } unset( $remainingTextInOpeningTag ); // check self closing if ($lastCharInRemainingText==='/') { $node->_[HDOM_INFO_ENDSPACE] .= '/'; $node->_[HDOM_INFO_END] = 0; } else { // reset parent if (!isset($this->self_closing_tags[strtolower($node->tag)])) $this->parent = $node; }
This is not the most beautiful code I've ever written, but it works :)
Could you refactor and add the fix to the next release?
The version I'm using is 1.11 ($Rev: 175 $)
Thanks a lot!
Author > Thank you! This works great. Others wanting to use this patch on 1.11 rev 175 - I found the line numbers to be 809-817 not 812-820, and on 185 it's 1200-1208.
Developers > Please apply this patch. Curly braces inside elements causes the parser to completely ignore the field / fail.
Last edit: Chumba Zumada 2012-11-27
Closing because this was fixed a long time ago. In current master you have to specify
$options = HDOM_SMARTY_AS_TEXT
to filter contents in curly braces.