verbb / cp-nav

Control Panel Nav is a Craft CMS plugin to help manage your Control Panel navigation.
MIT License
129 stars 11 forks source link

{siteUrl} support #8

Closed lindseydiloreto closed 9 years ago

lindseydiloreto commented 9 years ago

Sorry for blowing up your Github issues... :)

It would be great if the URL supported {siteUrl} to reference front-end pages. This is crucial for multi-environment setups.

example

lindseydiloreto commented 9 years ago

To clarify, I mean the ability to pull config values in as part of the URL...

screen shot 2015-03-20 at 1 05 23 pm

screen shot 2015-03-20 at 1 07 03 pm

In hindsight, {siteUrl} isn't really used anymore in these circumstances... Now, it's more often referred to as {baseUrl}.

engram-design commented 9 years ago

This is a great idea! Hadn't even thought about this :) Seems reasonably feasible.

lindseydiloreto commented 9 years ago

Check out how I did it in the CP CSS plugin... it's actually pretty straightforward!

engram-design commented 9 years ago

Nice one - that's pretty nifty!

engram-design commented 9 years ago

Hmmm - I'm no expert, but shouldn't this work in modifyCpNav()?

$nav[$newNav->handle] = array(
    'label' => $newNav->currLabel,
    'url'   => craft()->config->parseEnvironmentString(trim($newNav->url)),
);

Just keeps outputting the raw {siteUrl} tag...

lindseydiloreto commented 9 years ago

Do you have siteUrl defined in your environment variables? If not, it won't get parsed out at all.

To be honest, I kinda misspoke when I said siteUrl... These days, it's almost always referenced as baseUrl. There was a lot of confusion back in the day about what "siteUrl" meant in different contexts, so Brandon tweaked the docs to make "baseUrl" the standard for environment variables.

engram-design commented 9 years ago

Yeah, I have it defined, I've also tried baseUrl, which I've defined too. Strange.

lindseydiloreto commented 9 years ago

Weird, I'd think that would work.

Does your {baseUrl} tag contain any spaces? It shouldn't.

Try this for debugging:

$url = craft()->config->parseEnvironmentString(trim($newNav->url));

Craft::dd($url);

$nav[$newNav->handle] = array(
    'label' => $newNav->currLabel,
    'url'   => $url,
);

What does that output?

engram-design commented 9 years ago

I'm using $url = craft()->config->parseEnvironmentString('{baseUrl}/test'); just to be extra sure. It outputs {baseUrl}/test. What about you?

lindseydiloreto commented 9 years ago

I'm actually not testing on my end, but what you have looks right. Might be worth emailing P&T to find out what might be going on.

I feel like there's a 1% chance that perhaps the environment variables just haven't been set by the time modifyCpNav is called. Seems strange and unlikely, but I can't imagine what else might be causing the problem.

lindseydiloreto commented 9 years ago

Looks like you got this working beautifully!

It's only acting weird when you initially make the change... though I'm assuming it's using JS to change the nav tabs instantly.

engram-design commented 9 years ago

Good point, thats now fixed as well.

badlydrawnrob commented 8 years ago

Should {siteUrl} or {baseUrl} be working out of the box? Or do I have to modify something? It's just outputting trigger/{siteUrl}/path at the moment ...

lindseydiloreto commented 8 years ago

@badlydrawnrob: You'll need to have {baseUrl} defined in your environment variables...

engram-design commented 8 years ago

I'd love to have {siteUrl} available, but couldn't get it to work from memory. Might have another crack. In the meantime, as @lindseydiloreto points out, the {baseUrl} in your environment variables works a treat.

badlydrawnrob commented 8 years ago

@engram-design yup, would be handy to have if it's doable. @lindseydiloreto Hmm, {baseUrl} is defined but it just isn't working for me (outputting as if it's a relative url as I've mentioned earlier). I have cpTrigger set, some front-end form settings and the following:

'.dev' => array(
  'devMode' => true,
  'siteUrl' => 'http://site.dev/',

  'environmentVariables' => array(
    'basePath' => '/home/vagrant/site/html/',
    'baseUrl'  => 'http://site.dev/',
  ),
  'enableTemplateCaching' => false,
),
engram-design commented 8 years ago

@badlydrawnrob Ah - you're certainly correct, there's a minor bug that caused this not to work, which is now fixed in the 1.7.2 release

badlydrawnrob commented 8 years ago

@engram-design Perfect. That'll save me some headaches between dev/live deploys :+1: ... is it safe to just replace the plugin folder?

engram-design commented 8 years ago

FYI - {siteUrl} is now supported in the 1.7.3 release.