craftsmancoding / assetmanager

Asset Manager for MODX Revolution
36 stars 15 forks source link

Absolute url #35

Closed EkoOne closed 9 years ago

EkoOne commented 9 years ago

The goal is to have assets use an absolute url. I changed the following assman settings:

Asset Manager Site URL:[[~1]] or [[++site_url]] (neither works) URL Override: Yes

The problem is that neither tag gets parsed (is that the correct term?). So instead of the url being formatted as: https://mysite.com/assets/lib/ ...

it looks like this: [[++site_url]]assets/lib/ ...

The only way to get it to work is hard-coding it as: https://mysite/. Not ideal.

fireproofsocks commented 9 years ago

Can you paste the exact HTML from your template? If you are using a Snippet, please paste the exact Snippet call here.

EkoOne commented 9 years ago
[[$Head]]

<body>

    <div class="wrapper">
        <div class="content">
[[Wayfinder?
    &startId=`0`
    &limit=`5`
    &level=`1`
    &outerTpl=`Outer Menu`
    &rowTpl=`Menu Row`
    &lastClass=`last`
    &scheme=`https`
]]

[[!SimpleSearchForm?
    &tpl=`Search Form`
    &landing=`17`
    &highlightTag=`strong`
    &ids=`[[getReqParam? &name=`parent`]]`
    &containerTpl=`Refine Search`
]]

[[Breadcrumbs?
    &currentAsLink=`0`
    &showCurrentCrumb=`0`
    &showHomeCrumb=`0`
    &homeCrumbTitle=`Origin`
    &crumbSeparator=`&rangd;`
]]
            <section class="specs">
[[$Contributor]]
            </section>

            <article>
                <h2><a href="[[~[[*id]]]]">[[*pagetitle]]</a></h2>
                <div class="postMeta">
                    <p>[[*publishedon:strtotime:date=`<span>%m. %d.</span><br><b>%Y</b>`]]</p>
                </div>
                <div class="entry">
[[getPageAssets]]
                </div>
            </article>

            <footer>
                <p>[[Copyright]]</p>
            </footer>
        </div>
    </div>
</body>
fireproofsocks commented 9 years ago

So, you're using the getPageAssets Snippet to print out the asset? It should require the innerTpl parameter (see https://github.com/craftsmancoding/assetmanager/wiki/getPageAssets) so I'm not sure why that's working for you.

EkoOne commented 9 years ago

I don't know either, but it's definitely working.

That page was thrown together as a quick-n-dirty test. I only recently found assman and wanted to give it a brief test which is why I haven't added any parameters yet.

fireproofsocks commented 9 years ago

You may be able to adjust the URL used here simply by editing the media source.

EkoOne commented 9 years ago

That was one of the first things I changed when I went to SSL. It works fine for everything else except assman which is what I found odd. I suppose it's possible there's something screwy going on with my local setup but if it works elsewhere (locally) I kind of doubt it's the configuration.

fireproofsocks commented 9 years ago

Hmmm... maybe Asset Manager isn't reading the URL/path configurations from the Media Source correctly.

EkoOne commented 9 years ago

That's what I thought, but not knowing enough about such things it's at best a highly uneducated guess on my part.

fireproofsocks commented 9 years ago

I think the problem is here: https://github.com/craftsmancoding/assetmanager/blob/master/model/assman/asset.class.php Lines 331 to 348

fireproofsocks commented 9 years ago

Can you simply adjust the assets_url setting in the core/config/config.inc.php ? Or does editing the link_tag_scheme system setting affect the way the asset_url is generated? Just checked: link_tag_scheme does NOT affect the asset_url.

You should not need to hard-code anything here -- you can set the assman.url_override to true and then use whatever assman.site_url you want to generate the URL, but system settings aren't parsed, so you can't reference one system setting from another.

Or you could just update the asset_url in the config.inc.php

See https://github.com/craftsmancoding/assetmanager/wiki/Settings

EkoOne commented 9 years ago

Can you simply adjust the assets_url setting in the core/config/config.inc.php ? Or does editing the link_tag_scheme system setting affect the way the asset_url is generated?

Good question. I suppose the assets url could be adjusted via the config file. I always, for the sake of hardening the installation, modify the config file anyway (change folder names), though I never tried changing a url setting.

I’m not certain if the link_tag_scheme affects the asset_url.

You should not need to hard-code anything here -- you can set the assman.url_override to true and then use whatever assman.site_url you want to generate the URL, but system settings aren't parsed, so you can't reference one system setting from another.

See https://github.com/craftsmancoding/assetmanager/wiki/Settings https://github.com/craftsmancoding/assetmanager/wiki/SettingsThat's the thing with those settings: they work, but only if I hard-code https://mysite.com/ into the assman.site_url field.

Have you tried this on your installation? Can you get it to generate an absolute url without hard-coding it as I did above using one of the alternative methods you suggested? If you can then clearly the problem is specific to my setup and not MODX or assman.=

fireproofsocks commented 9 years ago

It looks like editing the config.inc.php doesn't work very well... but you can override the URL using the Asset Manager System Settings, as I outlined above, e.g.

I have tried that, and we use that: that's why those system settings were built. You have to put in the full URL but I wouldn't really call it "hard-coding" because it is a configuration setting. The only problem that you're having here is that system setting values aren't parsing placeholders, but that's the expected behavior.

So after all of this, I'm not sure if this is a valid issue: you have a way to set this.

EkoOne commented 9 years ago

Fair enough. It seems I was using the wrong terminology which caused some confusion.

Since I don’t understand the inner workings of the system I assumed that using something like [[~1]] would Just Work™ as it does elsewhere in MODX, but now I know better. I learned something new.

Thank you for your help. Great addon, by the way.

Todd

It looks like editing the config.inc.php doesn't work very well... but you can override the URL using the Asset Manager System Settings, as I outlined above, e.g. assman.url_override => true assman.site_url => https://yoursite.com/ https://yoursite.com/ I have tried that, and we use that: that's why those system settings were built. You have to put in the full URL but I wouldn't really call it "hard-coding" because it is a configuration setting. The only problem that you're having here is that system setting values aren't parsing placeholders, but that's the expected behavior.

So after all of this, I'm not sure if this is a valid issue: you have a way to set this.

— Reply to this email directly or view it on GitHub https://github.com/craftsmancoding/assetmanager/issues/35#issuecomment-66312730.

fireproofsocks commented 9 years ago

Most areas in MODX are parsed (content, chunks, TVs), so the [[++settings]] placeholder tags are parsed, but the system settings values aren't parsed. That makes sense I guess, but I didn't know that was the behavior off the top of my head -- parsing system setting values could create a loop condition and the parser is added overhead, so I guess it's sensible to omit the parsing behavior in that spot.

I don't think forcing HTTPs is really a valid use case here however... the assets on the page will be loaded using the same protocol as the rest of the page (unless you specifically use a fully qualified URL including http:// or https://). A better example of this use-case is when you'd like to use a CDN or a custom port where the URL is potentially pointing to a completely different host. Asset Manager does give you a way to accommodate that, but the Q here is whether MODX can/should.

fireproofsocks commented 9 years ago

Interesting: Jason weighed in: http://forums.modx.com/thread/95389/full-assets-url-ok-to-hard-code-value-in-config-inc-php#dis-post-516439

You CAN reference at least some other system settings, but it uses a special syntax: e.g. {url_scheme}{http_host}{assets_url}

You can also workaround this by creating a context setting and setting it specifically there (instead of modifying the config.inc.php). Learned something more...

EkoOne commented 9 years ago

Thanks. I’ll look into Jason’s suggestions.=

EkoOne commented 9 years ago

Just to follow-up:

As Jason suggested I created a new ‘assets_url’ System Setting and it worked perfectly.=