On Tue, Oct 21, 2008 at 01:52:02PM +0200, Maciej ?ebkowski wrote:

> I don`t think it is possible. ;-) It relies too much on the user input.
> 
> For example, the content of the page (markdown syntax) can be
> extended with some data from atom feed. But I dont know WHERE
> to insert this data. The user could write something like:
> 
>    This is paragraph
> 
>    <tal:block metal:use-macro="atom/contents" tal:define="entry feeds/main/2" 
> />
>      -- this will be replaced with contents of main atom feed, second entry.
> 
>   or some pseudosyntax like: [insert CONTENTS from main/2]
> 
> 
> And all of the above is *content*, insertet to the template using:
> 
>    <tal:block tal:content="structure markdown: content" />
> 
> So i guess the best solution is to use another expression modifier?
> 
>   <tal:block tal:content="structure markdown: expand_atom: content" />
> 
> (i don`t know if they can be chained, but thats not a problem)
> And in the modifier I have access to my data via $ctx object, right?

i wrote a wrapper for it. it is just an object, that wrapps the DOM and
provides as an object in tal.  the whole thing is barely 100 lines of code.
all the cruft around you can imagine your self.  to fetch the data it looks
like this:

/**
 *
 */
function __get($key) { #{{{
        if (strpos($key, "@")===0) {
                $key = substr($key, 1);
                if ($this->node->hasAttribute($key)) {
                        return $this->node->getAttribute($key);
                }
                return NULL;
        }
        if ($this->node->hasChildNodes()) {
                $forcelist = false;
                if (strpos($key, '[]')!==false) {
                        $key = substr($key, 0, strlen($key)-2);
                        $forcelist = true;
                }
                $ret = array();
                for ($i=0; $i<$this->node->childNodes->length; $i++) {
                        $child = $this->node->childNodes->item($i);
                        if ($child->nodeName==$key) {
                                if (!isset($this->domtalnodes_cache[$i])) {
                                        $this->domtalnodes_cache[$i] = new 
DOMTALNode($child);
                                }
                                $ret[] = $this->domtalnodes_cache[$i];
                        }
                }
                if (!$forcelist) {
                        return $ret[0];
                }
                return $ret;
        }
        return $this->node->nodeValue;
} #}}}

-- 
cu

Attachment: pgpmudY3pRFNt.pgp
Description: PGP signature

_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to