Redirect / for non-logged in users?

Just copy and paste riking’s script here into </head> in Admin -> Customize -> CSS/HTML to have the logo redirect to /latest.

To make categories the landing page, go to Admin -> Site Settings -> Basic Setup and make categories the first entry in the list for the top menu setting.

3 Likes

Works a treat :smiley:

Thanks so much for quick reply.

My new forum setup is coming along nicely
http://community.openenergymonitor.org. So much nicer than our old Durpal 6
PHP setup http://openenergymonitor.org/emon/forum

1 Like

Uh - and @Yuun’s code broke again:

Error: Could not find module discourse/components/home-logo

Where did that disappear to? Did a quick recursive grep, but came up with nothing?!

It’s broke because the new header.

Yup, seen that, thanks. I guess I will x-post my question there since it belongs to that new addition.

I’ve added a new widget setting to customize that url in this commit:

https://github.com/discourse/discourse/commit/02f771e66ead3fb6e861bfa1fd41d8c65d10ab1d

Here’s an example of how to use it via a customization:

<script type="text/discourse-plugin" version="0.4">
  api.changeWidgetSetting('home-logo', 'href', '/new-url')
</script>

Just replace /new-url whatever you want the path to be and you should be good to go.

7 Likes

I want to change the behavior of the home logo only when users are at my home page (window.location === ‘example.com/forum/’).

Should passing a function as the third parameter work?

Hmmm, how did you do that before? I thought targetUrl was just a parameter?

Thanks a lot Robin - looks great. Only that the snippet you posted just gives me this error:

TypeError: Attempted to assign to readonly property.

or, on Chrome:

Uncaught TypeError: Cannot set property 'href' of undefined

…and makes the whole header disappear.

I guess I’m just missing something here?

Did you get the latest master first? I tried it locally and it worked fine.

That’s the first thing I did before trying it! Is there a special section where I have to put the script code?

Aha it seems the tests-passed branch failed to build due to a failing test. I’m fixing it now.

edit: fixed the test. Give it 15-20 mins and it should have a new version for you.

2 Likes

Sorry, this was done in a hurry :laughing:

  window.goToPortal = function() { 
      if (window.location.href === 'https://example.com.br/forum/') { 
          window.location = 'https://example.com.br';
      }
  };

  var HeaderView = require('discourse/views/header').default

  HeaderView.reopen({
    didInsertElement : function(){
      this._super();
      Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
    },
    afterRenderEvent : function(){
      var logo = $('img#site-logo.logo-big').parent()[0];
    
      logo.addEventListener('click', window.goToPortal, false);
    }
  });

Can you help me @eviltrout ?

Like a charm. Thanks!

Hmmm that is a little complicated to establish in the new settings. Does adding that event work in the case where the url is not https://example.com.br/forum/ ? It seems the click handler would do nothing.

Yes, when the user isn’t at the forum home, I want the normal behavior (scroll up / go back to home).

Only when we are already at the forum home, I want to go back to my Portal home.

It’s quite tricky to do what you’re asking, because once an event is handled from the logo it prevents default.

I’ve added the ability for the href setting to be a function. Whatever value you return will be the destination when the user clicks the logo:

https://github.com/discourse/discourse/commit/1ac6dd194d811d4bb5609562dc52176ce2bdc34f

3 Likes

Should this work?

<script type="text/discourse-plugin" version="0.4">
  api.changeWidgetSetting('home-logo', 'href', function() { 
          return 'https://example.com.br';
  });
</script>

EDIT:

Setting it to ‘/another/page’ when using Discourse under ‘/forum’ also breaks :sadpanda:.

1 Like

This should fix it:

https://github.com/discourse/discourse/commit/4875fe1c3ea3865f4f37fe71fc8358c8c6341a07

5 Likes

I’ll test this later today! Thanks! :heart:

1 Like