This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi! I'm working on a project for a client and the website is a video platform behind a paywall. There's a version of the site with trailers only, you can browse content but cannot access the full feature set and content. It's like two different portals within the same project/website. The thing is, I want to replicate the URLs as they always were so SEO doesn't mess up.
Once a user is logged in, the same content is accessed (but with more features and full video) and there's a /member/
prefix added to the URI.
So i.e. if /video/that-movie
was displaying a trailer, then once logged in /member/video/that/movie
would display the full movie.
1) What would be the best way of achieving this behavior?
2) HARDMODE: Would it be possible to apply this same tweak for other plugins? (blog, static pages, forms, builder)
Basically, I guess if it's possible to set a token when /member/
is in the URI so that every partial/component/plugin can check if that token exists and tweak the content accordingly? Something like that?
Any suggestions are welcome, thanks and have a nice day!
Last updated
This sounds like you could simply access the information from the user's session
{% if member.hasSubscription %}
<!--- Show full video -->
{% else %}
<!--- Show trailer -->
{% endif %}
All you'd need to do is code the logic for the member.hasSubscription
check. Ultimately the restriction occurs on the front-end and any access points to sensitive material would be gated, also by the front-end
daftspunk said:
This sounds like you could simply access the information from the user's session
{% if member.hasSubscription %} <!--- Show full video --> {% else %} <!--- Show trailer --> {% endif %}
All you'd need to do is code the logic for the
member.hasSubscription
check. Ultimately the restriction occurs on the front-end and any access points to sensitive material would be gated, also by the front-end
Yes ok this answers #2 I guess I could extend the Rainlab.User
plugin to add that property/logic to it?
As of #1, how could I handle the /member/
bit, routing-wise? (see question) Is there any way of building a routing middleware of some sort or plugin to achieve so?
Basically, I'd need all URIs prefixed by /member/
to access the same content as without the prefix. So to keep it very simple: /member/:rest_of_uri/
would access content from /:rest_of_uri/
. Any way of manipulating routes globally without breaking any plugins (i.e. to add that prefix)?
Thanks!
As far as I understand it, both your requests would be handled by daftspunk's answer. What am I missing?
I agree his answer is what I need but what I don't get is how can I code a method to check the routing so I can call it from anywhere in themes/partials/etc.?
i.e. for now I'm building a quick demo so I just need to make a method that will check if URI contains /member/
. I'd call that method from theme templates and partials. So I could do as he told me {% if isMemberArea() %}...{% endif %}
Where can I put that method so it's global through the theme?
Is it possible to add PHP functions to the layout like we can do for pages?
Any suggestion? Thanks
Yes, there is a php code section for layouts as well. The alternative is to register twig filters/functions as shown here:
https://octobercms.com/docs/plugin/registration#extending-twig
Ok so basically what I could do is: Build a plugin that I will use to register a custom twig function that I will be able to call from everywhere.
-
Question 1: how can I associate this plugin with my layout? or how can I include that plugin everywhere on the site? (so the method is callable from partials, layout, etc)
-
Question 2: why can't I simply create a method in the code section of the layout here: http://0x0.st/zDDW.png and call it from other places in the templates/layout?
Thanks, I'm almost there! :D
Figured it out. This was simple as expected. Just added:
function onStart() {
// checking if /member/ is in URI
$this['isMemberArea'] = (strpos(Request::path(), 'member') !== false) ? true : false;
}
in the code section and in the template I did:
{% if isMemberArea %}
<p>this works!!!</p>
{% endif %}
I didn't needed anything more complex than this...
1-8 of 8