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

Set title of the Tag Page #30

Closed
wants to merge 2 commits into from
Closed

Set title of the Tag Page #30

wants to merge 2 commits into from

Conversation

terabin
Copy link

@terabin terabin commented Aug 28, 2016

All Tag Pages have the same forum Title, it's a good idea change the title when you visit a new tag.

All Tag Pages have the same forum Title, it's a good idea change the title when you visit a new tag.
@tobyzerner
Copy link
Contributor

tobyzerner commented Aug 28, 2016

Thanks for the PR! We have an issue for this somewhere too so that's good :)

Just one thing: the app.setTitle call should be made in the config method rather than view. This is because a call to view constructs the virtual dom, but doesn't guarantee that the page is actually being displayed - whereas config is only called once the page has definitely been rendered. See IndexPage in core as an example.

@terabin
Copy link
Author

terabin commented Aug 28, 2016

Just like this? The parameter IsInitialized is required?

@terabin
Copy link
Author

terabin commented Aug 28, 2016

Just a question, ClientView set the title for search engines, so, the correct way to do this is changing the php file too right?

Another point, if ClientView set first title, why the function setTitle is called when app start?
I am newbie in flarum install and compile methods, in github core, I can't find the ClientView. :(

@tobyzerner
Copy link
Contributor

Yes, that's correct, setting the title in PHP is necessary to set the title for search engines. It's necessary to set the title in both PHP and JS because Flarum is a single-page application, meaning users can navigate between a tag page and a discussion, and then back to a tag page, without hitting the server for new HTML.

So this is a little more tricky... The route for a tag page is defined in Listener\AddClientAssets on line 55. Currently it does not point to a custom controller, which means it'll just use the default WebAppController and then when the JS app boots it will see the current URL and load the correct discussion list. A new controller called TagController needs to be created which extends WebAppController, injects a TagsRepository instance, and overrides the getView method:

    protected function getView(Request $request)
    {
        $view = parent::getView($request);

        $slug = array_get($request->getQueryParams(), 'slug');
        $actor = $request->getAttribute('actor');
        $tag = $this->tags->query()->whereVisibleTo($actor)->where('slug', $slug)->firstOrFail();

        $view->setTitle($tag->name);

        return $view;
    }

Ultimately this controller should extend IndexController and preload the discussion list too, but let's not worry about that for now.

Also, something else I didn't notice on my first pass: in the JS you're setting the title in the TagHero component, but the presence of this component is not technically synonymous with being on a tag page... The title should really be set in the extension of the IndexPage component in addTagFilter.js:

  extend(IndexPage.prototype, 'config', function(value, isInitialized) {
    if (isInitialized) return;

    const tag = this.currentTag();

    if (tag) {
      app.setTitle(tag.name());
    }
  });

Sorry to be nitpicky, but it's good to do these things right :)

@terabin
Copy link
Author

terabin commented Aug 28, 2016

I'm studying the Flarum, then surely I will need advice, thanks!

But I did not understand well, my Core does not have the same structure as the current Core ,although the latest version .

Currently, information is passed to the app.blade by ClientView.php in render function.

The correct would be to override this function, create TagRepository and consult the data by the slug, is not it?

@tobyzerner
Copy link
Contributor

I'm guessing you're using beta 5 - but the ClientView code has been completely refactored in dev-master. You'll need to update if you want to want to contribute :)

@franzliedke
Copy link
Contributor

@terabin Do you need further help to get started with the PHP side of things?

@terabin
Copy link
Author

terabin commented Sep 12, 2016

@franzliedke, any help surely be welcome. I will start this way today.

@luceos
Copy link
Member

luceos commented Nov 2, 2017

@flarum/core what to do with this? As suggested on discord#staff I'd like to propose to close stale PR's based on old code.

@tobyzerner
Copy link
Contributor

tobyzerner commented Nov 5, 2017

I'm closing this due to inactivity. The full explanation in my comment above still stands.

Relevant issue is flarum/framework#495.

@tobyzerner tobyzerner closed this Nov 5, 2017
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.

4 participants