0

I need to have PHP on "input" instead of "output" (to feed some tags) so I can't use PHP to change the value of a tag. Is there either a built in function to handle this, or a way to make my own tag that can take another tag's value as input?

What I have now:

{exp:channel:entries channel="test"}
    {image}
        <picture>
            <source srcset="{path}/_mobile/{filename}.{extension}" media="..." />
            <source srcset="{path}{filename}.{extension}" media="..." />
        <picture>
    {/image}
{exp:channel:entries channel="test"}

But the {path} is absolute and I want it to be relative (to handle https vs http). How would I do this?

1

Well, of course there is a way. It depends on why you are going about it this way.

First, I assume the {path} variable can go to different domains (possibly a channel you'll duplicate over many MSM sites?) and is user entered, and isn't necessarily the domain of the application. If it were, you could just use {site_url} or hard-code the path to your folder with those files.

One way to handle it is to tell people not to enter any protocol; the responding server will handle the protocol and redirect to HTTPS if that is the only protocol it wants to serve. You can put instructions to that field in your field settings.

Are you intending on letting your app serve both HTTP and HTTPS? It isn't good practice these days to do that at all. You should just be behind a certificate with a modern encryption-suite.

BUT... anyways, to do this, use a plugin. Sure, you could craft your own, but no need. Use CE String or Low Replace:

http://www.causingeffect.com/software/expressionengine/ce-string

http://gotolow.com/addons/low-replace

Both fine candidates. Look at their documentation, and it will allow you to do string manipulations on that {path} variable. An example might be:

{replace:plugin find="http://|https://" replace=""}{path}{/replace:plugin}
2
  • Thank you. It's not people entering the protocol. This path is just from retrieving am image from a channel entry. EE returns it that way. I would prefer to get the relative path but cannot find how to do that.
    – Don Rhummy
    Dec 28 '15 at 1:18
  • If you could give some example field inputs for the path field, and the output you want, we can help you even more. Please include variations of inputs that you need to parse as well as the possible different outputs (if the output isn't uniform).
    – jrothafer
    Dec 28 '15 at 3:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.