I would like to check in global scrapbook for a particular name, and then do something if it does.

Permalink
Hello, I would like to figure out how to check if a certain name exists in the global scrapbook, and then do something if it does exist, like use an "if" statement to determine whether or not to output html to a page.
An example use case would be to create many color versions of a theme, and name individual CSS files to match that color scheme for that theme. Then you would create an if/else statement to check for a particular color name in the global scrapbook (I wouldn't care what kind of block it was, I just need the name of it), and output the css based on that name.
Is this possible? I know you can change a line in the HTML to do this, but I want a seamless and code-less way for the user to change between many color variations in a theme. I am also aware of the user theme switcher block in the marketplace but that is more for theme demoing rather than a end user solution.

Any ideas?

boomgraphics
 
jordanlev replied on at Permalink Best Answer Reply
jordanlev
You can check for the existence of a scrapbook block with a certain name using the following code:
$block = Block::getByName('Your Block Name');  
if ($block && $block->bID) {
    //The block exists
} else {
  //No block :(
}


BUT, I think a better way to achieve what you want is by using a page attribute -- see these:
http://www.concrete5.org/community/forums/customizing_c5/themes-and...
http://www.concrete5.org/community/forums/customizing_c5/background...
http://www.concrete5.org/community/forums/themes/customising-theme-...
boomgraphics replied on at Permalink Reply
boomgraphics
ah beautiful. Unfortunately I can't use the page attribute bit because I need it to change the entire site's css whenever you input a certain name (because my color schemes would change all images to match, as well). Perhaps when I am a bit more familiar with PHP I'll make a CSS changer block for the end user.

BUT, your links gave me some fantastic ideas for other features on a page by page basis.

Thanks!
jordanlev replied on at Permalink Reply
jordanlev
You can still use page attributes -- just put a <style> tag in your theme's header, and put the appropriate styles there instead of the css file (because in the theme template you can use PHP to output different CSS as appropriate).
boomgraphics replied on at Permalink Reply
boomgraphics
Well, it would be nice to be able to do that, but I can't. First, in making themes as comprehensive as the ones I am planning, the CSS will run into thousands of lines. Of course I would minify the files, but they still need to be cached (by the browser) to make for good subsequent page load speeds. From what I see of the page attributes, the user would have to add the attribute to each page and select the color scheme. That obviously wouldn't work for a site with a huge number of pages, if all the user wanted to do was change the global site color scheme. Of course, I would also incorporate a parsed CSS file for fonts and what not, but they do need to be cached.
jordanlev replied on at Permalink Reply
jordanlev
Ah yes, well if you plan on having literally thousands of lines of CSS and tons of pages, then you are correct that this won't be a sane approach.

Good luck with the site, sounds like a very interesting project!

-Jordan
boomgraphics replied on at Permalink Reply
boomgraphics
lol thanks. And yes, literally thousands of lines of CSS. I never thought anyone would ever use that much CSS, until I saw a wordpress theme that was quite beautiful, so I checked out the CSS. It was over 1500 lines on just one of the includes. There were other CSS includes too. So I realized that to make the most comprehensive theme in the marketplace I would have to have a huge amount of CSS and a lot (a LOT) of custom jQuery.
Me and my brother are going to start by defining a "framework" for the rules and the custom functionality that will be standard across all our themes, and then the prices will be low, so hopefully it will equate into a winning combination, lol.

Also, I had a concern about the block auto including view.css files in the header. I know IE has a limit of around 34 css includes, so what happens when your site uses more than 34 different blocks with separate view.csss files? So we will be making and compiling view templates into a free block that replaces all view templates for the core blocks and allows their code to interact with some really beautiful jQuery, and also merge all their css into one file (main.css).