Thread: [Formsess-devel] smarty-vars/functions in fs-tags
Status: Beta
Brought to you by:
mrkatana
|
From: David <da...@df...> - 2003-12-10 08:00:39
|
Hello,
I modified _glueAttributes in FormsessTag a little bit and now using
smarty vars, functions or whatever you want should be possible.
This is the modified function:
===
function glueAttributes() {
$captures = '';
$string = '';
foreach ($this->attributes as $name => $value) {
if (!$value or ($value == 'false')) {
//don't know what that means..
$format = ' %s=%s';
} elseif ($this->_fs_filter->_isSmartyVar($value)) {
//we can use a single var directly
$value = $this->smartyVariableRemoveDelimiters($value);
$format = '%s=%s';
} elseif (strpos($value, $this->_fs_filter->smarty_ldelim) !== false) {
//we need to capture the value
$captures .= $this->smartyEmbed('capture assign="fs_capture_' . $name . '"')
. $value . $this->smartyEmbed('/capture');
$value = "fs_capture_{$value}";
$format = '%s=%s';
} else {
//value is a simple string
$format = ' %s="%s"';
}
$string .= sprintf(' %s="%s"', $name, $value);
}
return $captures . $string;
}
===
That should work, however because the current version doesn't work I
didn't test it at all..
The basic thing is capturing everything that contains a smarty-delimiter
and is "more" than a simple variable.
Btw: I'm not sure if _isSmartyVar works the way it should here since it
allows whitespace before and after a var.
I did not use getAttributesNames() and getAttributeValue, accessing
$this->attributes directly is much easier.
Just tell me what you think about it..
David
ps: I don't understand the purpose of the first check, if (!$value or
($value == 'false')), why passing empty parameters unquoted to the
smarty-functions? ($format = ' %s=%s';)
|
|
From: Katana <ka...@ka...> - 2003-12-10 08:22:46
|
> I modified _glueAttributes in FormsessTag a little bit and now using
> smarty vars, functions or whatever you want should be possible.
I have added your implementation to the method in CVS. However, I fear
that something might be wrong:
glueAttributes just returns a string with arguments ready to be used in
a smarty function call. If another smarty function call (capture) is
inserted in that string, we will probably end up with a parse error
won't we ?
{fs_input_text name="foo" {capture ...
We probably need to
- keep in a property the list of captures
- return from glueAttributes with a string containing the capture
names when needed
- prepend the captured captures (ahaha.. ahem, right) to the tag
string before it is returned.
What do you think about that ?
> I did not use getAttributesNames() and getAttributeValue, accessing
> $this->attributes directly is much easier.
Sorry but I have removed that. I'd rather avoid as much as possible to
access properties directly. Accessors are in my opinion better,
especially here, since I intend to change the way attributes are handled
later on. However it's just the same :)
> ps: I don't understand the purpose of the first check, if (!$value or
> ($value == 'false')), why passing empty parameters unquoted to the
> smarty-functions? ($format = ' %s=%s';)
In fact, "false" to smarty does not work with a few functions, so It was
necessary to use a different format in order to pass something that
smarty really understands as !true.
--
Katana
|
|
From: David <da...@df...> - 2003-12-10 10:16:08
|
On Wed, 10 Dec 2003 09:22:40 +0100
Katana <ka...@ka...> wrote:
> glueAttributes just returns a string with arguments ready to be used
> in a smarty function call. If another smarty function call (capture)
> is inserted in that string, we will probably end up with a parse error
>
> won't we ?
You're right.. I should have looked a little closer to the context..
> {fs_input_text name="foo" {capture ...
> We probably need to
> - keep in a property the list of captures
> - return from glueAttributes with a string containing the capture
> names when needed
Yes, what do you think about that:
adding another property 'captures' to FormsessTag
var $captures;
initialising it onthe constructor:
$this->captures = array();
and accessing it via glueAttributes:
===
function glueAttributes() {
$string = '';
$atts = getAllAttributes();
foreach ($atts as $name => $value) {
if (!$value or ($value == 'false')) {
$format = ' %s=%s';
} elseif ($this->_fs_filter->_isSmartyVar($value)) {
//we can use a single var directly
$value = $this->smartyVariableRemoveDelimiters($value);
$format = '%s=%s';
} elseif (strpos($value, $this->_fs_filter->smarty_ldelim) !== false) {
//we need to capture the value
$value = 'fs_capture_' . count($this->captures);
$this->captures[] = $value;
$format = '%s=%s';
} else {
//value is a simple string
$format = ' %s="%s"';
}
$string .= sprintf(' %s="%s"', $name, $value);
}
return $string;
}
===
> - prepend the captured captures (ahaha.. ahem, right) to the tag
> string before it is returned.
I'm not sure how to accomplish that.
One solution is building a function adCaptures($string) that simply adds
the capture-tags to the given smarty-function and is called by the
extending function at the very end.
like
function addCaptures($string) {
$tmp = '';
foreach($this->captures)
//add capturetag tp $tmp
return $tmp . $string;
}
And in the extending functions for example:
return addCaptures($this->smartyEmbed('fs_html_select_date' . $this->glueAttributes()));
I'm not very happy with that, maybe you have a better idea..
Another thing: the input.class.php does that:
$string = 'fs_input_' . $this->getAttributeValue('type') . ' name="' . $this->getAttributeValue('name') . '"';
$this->deleteAttribute('type'); $this->deleteAttribute('value');
Which prevents the name and type attribute from beeing captured.
Is there any reason not to handle them like the other attributes?
David
|
|
From: Katana <ka...@ka...> - 2003-12-10 10:48:14
|
David,
just about our little {capture}'s, I just stumbled (again) upon smarty
backticks syntax: don't you think it would be good to implement them as
long as only variables are used as formsess tags parameters ?
http://smarty.php.net/manual/en/language.syntax.quotes.php
For functions, of course, capture is required.
--
Katana
|