Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Helper\Title::get() #43

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

jakejohns
Copy link
Member

This makes it so I can get the text of the title property without the HTML for
use elsewhere in a layout. For example:

<?php
// page.php

$this->title('Page Title');
//...
<?php
// layout.php

$this->metas()->add(
    'name' => 'title',
    'property' => 'og:title',
    'content' => $this->title()->get()
);

$this->title()->prepend('Site Title: ');
//...

Thoughts?

@harikt
Copy link
Member

harikt commented Jan 29, 2016

👍 for this. not spamming, but I understand sometimes this will help :) .

@pmjones
Copy link
Member

pmjones commented Jan 29, 2016

(/me nods)

If someone uses setRaw() or appendRaw(), and then get(), does that mess up your use case?

@harikt
Copy link
Member

harikt commented Jan 30, 2016

so @pmjones so may be you are proposing to use $this->escaper->html() inside get , and getRaw() a new method? So if they need raw data ?

@jakejohns
Copy link
Member Author

Ah.... There is an issue here, isn't there?

Well, I think there's some options.

1. Assume escaped, users responsibility

I think the idea is that when adding to the title, one is assuming they are
always keeping the title in a valid state, namely escaped for html. So the use
case above should be rewritten as:

$helper->metas()->add(
    [
        'name' => 'title',
        'property' => 'og:title',
        'content' => htmlspecialchars_decode($helper->title()->get())
    ]
);

However, this is a little weird as the HTMLEscaper may have
$flags and you'd want to get that from the escaper and pass them
to htmlspecialchars_decode.

2. Assume escaped, add ::get and ::getRaw

To avoid the onerous need to manually call decode, and get the flags, etc...
Perhaps the HTMLEscaper could use an additional method (unescape, or
decode, or something) which would allow for the reversing of the encoding.

// HTMLEscaper
// ...

public function unescape($escaped)
{
    return htmlspecialchars_decode(
        $escaped,
        $this->flags
    );
}

The Title helper could use this method internally in getRaw:

// Helper\Title
// ...
public function get()
{
    return $this->title;
}

public function getRaw()
{
    return $this->escaper->unescape($this->title);
}

3. Some other more convoluted paradigm

Alternatively, I guess we could try to store the 'parts' added to the title
string in some sort of structure which identified the 'escaped/unescaped' nature
of each piece and held off on escaping until later. I'm not sure this would be
completely useful though, as I think it implies that the user might want a title
in some kind of 'invalid state' at some point.

I think I like the 2nd option. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants