HeadMeta

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

HeadMeta

Ian Warner-2
Hi

I have this in my Layout script - setting some default Meta Data:

// Setting META Headers come from the Config File
if ($config->meta->keywords) {
    $this->headMeta()->appendName('keywords', $config->meta->keywords);
}

if ($config->meta->description) {
    $this->headMeta()->appendName('description', $config->meta->description);
}

echo $this->headMeta() . PHP_EOL;


Now in a View I want to overide so I call:
$this->headMeta()->setName('description', 'Words words words.');



I would expect there to be only one description on the site - but two are printed the default and the one from the view.
Is this a bug or expected behaviour - if so how do I make sure only one is visible.

Ian
Reply | Threaded
Open this post in threaded view
|

Re: HeadMeta

weierophinney
Administrator
-- Ian Warner <[hidden email]> wrote
(on Saturday, 10 October 2009, 02:38 AM +0900):

> I have this in my Layout script - setting some default Meta Data:
>
> // Setting META Headers come from the Config File
> if ($config->meta->keywords) {
>     $this->headMeta()->appendName('keywords', $config->meta->keywords);
> }
>
> if ($config->meta->description) {
>     $this->headMeta()->appendName('description', $config->meta->description);
> }
>
> echo $this->headMeta() . PHP_EOL;
>
>
> Now in a View I want to overide so I call:
> $this->headMeta()->setName('description', 'Words words words.');
>
> I would expect there to be only one description on the site - but two are
> printed the default and the one from the view.
> Is this a bug or expected behaviour - if so how do I make sure only one is
> visible.

Expected behavior; setName() sets the first element in the array.

You can *clear* what's in the array by passing an empty array to
exchangeArray(), as the containers extend ArrayObject:

    $this->headMeta()->exchangeArray(array());
    $this->headMeta()->setName('description', 'Words words words.');

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|

Re: HeadMeta

Ian Warner-2
I would have thought though that there can only be one Description so I need to do

// Layout Call
if ($config->meta->description) {
    $this->headMeta()->setName('description', $config->meta->description);
}

// View Call
$this->headMeta()->setName('description', 'Words words words.');

Trouble is the Layout call is getting processed afterwards and overwriting my view call - can I check if something exists in the array first and then decide to call the layout setName?

Cheers

2009/10/10 Matthew Weier O'Phinney <[hidden email]>
-- Ian Warner <[hidden email]> wrote
(on Saturday, 10 October 2009, 02:38 AM +0900):
> I have this in my Layout script - setting some default Meta Data:
>
> // Setting META Headers come from the Config File
> if ($config->meta->keywords) {
>     $this->headMeta()->appendName('keywords', $config->meta->keywords);
> }
>
> if ($config->meta->description) {
>     $this->headMeta()->appendName('description', $config->meta->description);
> }
>
> echo $this->headMeta() . PHP_EOL;
>
>
> Now in a View I want to overide so I call:
> $this->headMeta()->setName('description', 'Words words words.');
>
> I would expect there to be only one description on the site - but two are
> printed the default and the one from the view.
> Is this a bug or expected behaviour - if so how do I make sure only one is
> visible.

Expected behavior; setName() sets the first element in the array.

You can *clear* what's in the array by passing an empty array to
exchangeArray(), as the containers extend ArrayObject:

   $this->headMeta()->exchangeArray(array());
   $this->headMeta()->setName('description', 'Words words words.');

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/

Reply | Threaded
Open this post in threaded view
|

Re: HeadMeta

Ian Warner-2
Further to this I have been examining the Code to try and get at a property to see if it already exists:

I see this in: abstract class Zend_View_Helper_Placeholder_Container_Standalone

    /**
     * Overloading: retrieve property
     *
     * @param  string $key
     * @return mixed
     */
    public function __get($key)
    {
        $container = $this->getContainer();

        if (isset($container[$key])) {
            return $container[$key];
        }

        return null;
    }

However as the Container is a sequential object it would be lucky to get the property I want based on the key wouldn't it as I need to pass in an int value

Zend_View_Helper_Placeholder_Container Object ( [0] => stdClass Object ( [type] => name [name] => title [content] => Content. [modifiers] => Array ( ) ) [2] => stdClass Object ( [type] => name [name] => keywords [content] => keywords [modifiers] => Array ( ) ) [3] => stdClass Object ( [type] => name [name] => description [content] => description [modifiers] => Array ( ) ) )

What i want is the property based on the name.

Sorry if I am missing a trick here but just need to see if Description is already set if it is then do not set again.


2009/10/13 Ian Warner <[hidden email]>
I would have thought though that there can only be one Description so I need to do

// Layout Call
if ($config->meta->description) {
    $this->headMeta()->setName('description', $config->meta->description);
}

// View Call

$this->headMeta()->setName('description', 'Words words words.');

Trouble is the Layout call is getting processed afterwards and overwriting my view call - can I check if something exists in the array first and then decide to call the layout setName?

Cheers

2009/10/10 Matthew Weier O'Phinney <[hidden email]>

-- Ian Warner <[hidden email]> wrote
(on Saturday, 10 October 2009, 02:38 AM +0900):
> I have this in my Layout script - setting some default Meta Data:
>
> // Setting META Headers come from the Config File
> if ($config->meta->keywords) {
>     $this->headMeta()->appendName('keywords', $config->meta->keywords);
> }
>
> if ($config->meta->description) {
>     $this->headMeta()->appendName('description', $config->meta->description);
> }
>
> echo $this->headMeta() . PHP_EOL;
>
>
> Now in a View I want to overide so I call:
> $this->headMeta()->setName('description', 'Words words words.');
>
> I would expect there to be only one description on the site - but two are
> printed the default and the one from the view.
> Is this a bug or expected behaviour - if so how do I make sure only one is
> visible.

Expected behavior; setName() sets the first element in the array.

You can *clear* what's in the array by passing an empty array to
exchangeArray(), as the containers extend ArrayObject:

   $this->headMeta()->exchangeArray(array());
   $this->headMeta()->setName('description', 'Words words words.');

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/


Reply | Threaded
Open this post in threaded view
|

Re: HeadMeta

Hector Virgen
Another way around this would be to set your default description early (like in a bootstrap init method) and let your view scripts override it when necessary.

--
Hector


On Mon, Oct 12, 2009 at 7:07 PM, Ian Warner <[hidden email]> wrote:
Further to this I have been examining the Code to try and get at a property to see if it already exists:

I see this in: abstract class Zend_View_Helper_Placeholder_Container_Standalone

    /**
     * Overloading: retrieve property
     *
     * @param  string $key
     * @return mixed
     */
    public function __get($key)
    {
        $container = $this->getContainer();

        if (isset($container[$key])) {
            return $container[$key];
        }

        return null;
    }

However as the Container is a sequential object it would be lucky to get the property I want based on the key wouldn't it as I need to pass in an int value

Zend_View_Helper_Placeholder_Container Object ( [0] => stdClass Object ( [type] => name [name] => title [content] => Content. [modifiers] => Array ( ) ) [2] => stdClass Object ( [type] => name [name] => keywords [content] => keywords [modifiers] => Array ( ) ) [3] => stdClass Object ( [type] => name [name] => description [content] => description [modifiers] => Array ( ) ) )

What i want is the property based on the name.

Sorry if I am missing a trick here but just need to see if Description is already set if it is then do not set again.


2009/10/13 Ian Warner <[hidden email]>

I would have thought though that there can only be one Description so I need to do

// Layout Call
if ($config->meta->description) {
    $this->headMeta()->setName('description', $config->meta->description);
}

// View Call

$this->headMeta()->setName('description', 'Words words words.');

Trouble is the Layout call is getting processed afterwards and overwriting my view call - can I check if something exists in the array first and then decide to call the layout setName?

Cheers

2009/10/10 Matthew Weier O'Phinney <[hidden email]>

-- Ian Warner <[hidden email]> wrote
(on Saturday, 10 October 2009, 02:38 AM +0900):
> I have this in my Layout script - setting some default Meta Data:
>
> // Setting META Headers come from the Config File
> if ($config->meta->keywords) {
>     $this->headMeta()->appendName('keywords', $config->meta->keywords);
> }
>
> if ($config->meta->description) {
>     $this->headMeta()->appendName('description', $config->meta->description);
> }
>
> echo $this->headMeta() . PHP_EOL;
>
>
> Now in a View I want to overide so I call:
> $this->headMeta()->setName('description', 'Words words words.');
>
> I would expect there to be only one description on the site - but two are
> printed the default and the one from the view.
> Is this a bug or expected behaviour - if so how do I make sure only one is
> visible.

Expected behavior; setName() sets the first element in the array.

You can *clear* what's in the array by passing an empty array to
exchangeArray(), as the containers extend ArrayObject:

   $this->headMeta()->exchangeArray(array());
   $this->headMeta()->setName('description', 'Words words words.');

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/



--
Hector Virgen
Reply | Threaded
Open this post in threaded view
|

Re: HeadMeta

David Mintz


On Mon, Oct 12, 2009 at 11:55 PM, Hector Virgen <[hidden email]> wrote:
Another way around this would be to set your default description early (like in a bootstrap init method) and let your view scripts override it when necessary.



Let your view scripts override it when necessary -- that's exactly what I am not figuring out how to do.

My scenario is slightly different, but typical. I want my layout to detect if there's a logged in user; if so, display "Welcome User Foo" , otherwise display a link to the login page. No problem.

If, however, the current page itself is the login page, I want to suppress the welcome/log in message entirely. Thus, in my layout,

$this->placeholder('loginBox')->captureStart();?>
<div id="loginDiv">
<?php if ($this->user) :?>Welcome <?=$this->user->firstname?>
<?php else:?>
<a href="/users/login/" ></a>[log in]</a>
<?php endif;?>
</div>
<?php $this->placeholder('loginBox')->captureEnd();

and later in the layout script,

<?= $this->placeholder('loginBox')?>

Once I get into login.phtml, I can't seem to reset the content of the placeholder to empty string, or unset it, or otherwise prevent it from being displayed, having tried exchangeArray() and various other tricks. It seems it's already been output to the browser and that's that. What am I missing?

Thanks a million,

--
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness