Problems, need help? Have a tip or advice? Post it here.
16 posts Page 2 of 2
Sorry it took so long to test, but yes, this works! Since I'm using routes, this is the code I put on my pages:

my page header link:
Code: Select all
<cms:show k_site_link />css/style.php?page=<cms:show k_template_name />&post=<cms:show rt_name/>


my style.php page:
Code: Select all
<cms:pages masterpage="<cms:gpc 'page' />" page_name="<cms:gpc 'post' />" limit='1' ><cms:show page_img /></cms:pages>


Thank you very much, Anton!

That opens up a whole other world of being able to integrate dynamic data into what used to be a static page.

Thanks @kk, @trendoman and @genex for all of your help with this.

Is there a previous post that talks about adding gpc params to links like this?
@trendoman or @kk,

Can you think of any reason why this works flawlessly on my WAMP server, but when I take it to my live server, it doesn't appear that the php file is being read as a stylesheet at all?

I've tried many different troubleshooting techniques, most importantly, changing the name of the file to a .css extension (and of course removing the necessary php code) and I see that the file gets referenced as expected. I've stripped everything down to the bare minimum and even took off the query string params of the link and still, it will not get referenced as a stylesheet when I have it as a .php file.

I know the server is running php 8. I'm working with the hosting company. Can you think of anything I should pinpoint that I may point out to them?
@scratz,
when I take it to my live server, it doesn't appear that the php file is being read as a stylesheet at all?

Try accessing the file in the browser by using its URL in the address bar.
What do you get to see?

If it is not a 404 (or other) error, please use 'Inspect' of browser's dev-tools ('Network' tab) and check the 'content-type' of the received file.
It should be "content-type: text/css; charset=utf-8". If not, please make sure you are following this instruction from the original post -
Make sure to place the following statement just below the require_once
<cms:content_type 'text/css' />

Let us know.
Hello KK,

Thank you for your response. I'm not sure what the original problem was, but it is now working as expected.
I had done a lot of testing and swapping files between both my WAMP local and my hosted server during the building of this site. Because of this, and because the hosting support wasn't able to identify any reason it shouldn't work, I wiped the site clean and reinstalled.

This needed to be done anyway due to a lot of unnecessary files and structure on there.

After I reinstalled I verified as you'd suggested and I originally did have the <cms:content_type 'text/css' /> as well.

Everything looked good, I was able to access the page, under the Network tab under Heading I saw Status 200 OK as well as the "content type: content-type: text/css; charset=utf-8". Then I tested the pages that were not getting the php stylesheet and everything worked as expected.

So, again, I'm not sure why it wasn't connecting originally, but after a total wipe/reinstall, everything is fine. Thank you again for all your time and patience.
@scratz, I am glad the problem is resolved.
BTW, do you know about my theory of "Gremlins in the box" for such cases? :)
Hello again @KK and @Trendoman,

Well, upon further testing, there are some odd differences with this .php stylesheet being rendered on the front end but only, it seems, with the pagebuilder method.

I have a template that via css can put a color/gradient overlay over a section (these sections will become blocks in pagebuilder). I have my own .php file (configured as @trendoman suggested) as a stylesheet so a user can set whatever colors they want per block. There are the default colors of the site but through Couch's AMAZING CMS framework and all of the contributors and help in these forums, I can make it to where the user can choose their own custom colors to use. These colors are pulled from the editables and set as vars to use in the stylesheet:
<head>
Code: Select all
....
...
<link href="<cms:show k_site_link />assets/css/theme.css" rel="stylesheet" />
    <link href="<cms:show k_site_link />assets/css/user.php?page=<cms:show k_template_name />&post=<cms:show k_page_id />"
...
...


user.php
Code: Select all
<?php require_once( '../../smbcw_admin/cms.php' ); ?>
<cms:template parent='_donottouch_' hidden='1' />
<cms:content_type 'text/css' />
<cms:pages masterpage="<cms:gpc 'page' />" id="<cms:gpc 'post' />" >
    <cms:if img_ovrly>
        <cms:set overly_color1="<cms:show clr_one />" "global" />
        <cms:set overly_color2="<cms:show clr_two />" "global" />
    </cms:if>
    <cms:if rvrs_grad >
        <cms:set swap_clr="1" "global" />
    </cms:if>
......
.hr-med {
  width: 28rem;
  margin: 1.25rem auto;
}
.hr-long {
  width: 64rem;
  margin: 1.25rem auto;
}



.bg-holder.overlay-color:before {
  background: <cms:show overly_color1 />;
}

<cms:if swap_clr >
.bg-holder.overlay-gradient:before {
  background: -o-linear-gradient(135deg, <cms:show overly_color1 /> 0, <cms:show overly_color2 /> 100%);
  background: linear-gradient(-45deg, <cms:show overly_color1 /> 0, <cms:show overly_color2 /> 100%);
}
<cms:else />
.bg-holder.overlay-gradient:before {
  background: -o-linear-gradient(135deg, <cms:show overly_color2 /> 0, <cms:show overly_color1 /> 100%);
  background: linear-gradient(-45deg, <cms:show overly_color2 /> 0, <cms:show overly_color1 /> 100%);
}
</cms:if>



If I build a page from a regular template, with all the code on a single page (as opposed to pagebuilder), everything works great in Admin and on the front-end site - no problems.

However, in pagebuilder, as the blocks are being created, while still in the Admin section, everything works beautifully as expected. So, obviously the style is cascading from the php stylesheet and all of the querystring parameters are working. I build the blocks, and with the blocks I create a page. Even after I save the page, re-edit it, re-save it, everything renders perfectly in the Admin section - each block looks and renders as it should.

However when the page renders on the front end, whether it's my testing server or my hosting server, the front end won't show the custom colored overlay, but it WILL show it's default overlay. This means the element style is being read but the style isn't coming from the php stylesheet, only the default site one. I can tell from other styling on the rendered front-end page that SOME of the php style is referenced (namely, the .hr-med and .hr-long ) so I know the php style sheet is being referred to by this page.

But why isn't the color coming through? The "source" shows the correct style inside the html element. Couch is rendering all of the editables on the page correctly and when I look at <head> and look at the Source / Network tab, the link shows the correct query params and that it's a UTF-8 css/text stylesheet. Again, some of that coding is getting pulled which is proof it's getting referred.

I was thinking the issue was because 1 page would now be trying to render the same variable at different parts of the page because of the distinct blocks (overly_color1, overly_color2). And I'm not sure that's not it, but then why would it work fine in the Admin section? Is it because the Admin section is iFrames? But even if that were the case, wouldn't at least the first color, or the last colored block render correctly?

I'm totally at a loss as to why the colors aren't being pulled and rendering. Has anyone else come across anything like this?
16 posts Page 2 of 2