What is wrong with my page_theme that would not work

Permalink
Hi,
I would really appreciate some help understanding what I am doing wrong ... each tutorial I read gives a different code and I am getting lost with something that sounds so easy and ends up making me feel like I should just play ping pong rather than keeping making websites !! :-)

Would anyone be kind enough to explain how this asset system works as whatever code I try I still stumble into Javascript conflicts.

Here is my code.

<?php 
namespace Application\Theme\Citytour;
use Concrete\Core\Area\Layout\Preset\Provider\ThemeProviderInterface;
class PageTheme extends \Concrete\Core\Page\Theme\Theme implements ThemeProviderInterface
{
    public function registerAssets()
    {
        $this->providesAsset('javascript', 'bootstrap/*');
        $this->providesAsset('css', 'bootstrap/*');
        $this->providesAsset('css', 'blocks/form');
        $this->providesAsset('css', 'blocks/social_links');
        $this->providesAsset('css', 'blocks/share_this_page');
        $this->providesAsset('css', 'blocks/feature');
        $this->providesAsset('css', 'blocks/testimonial');
        $this->providesAsset('css', 'blocks/date_navigation');



Many thanks in advance.

 
mnakalay replied on at Permalink Reply
mnakalay
Hello,

you are using 2 different asset function
providesAsset()

and
requireAsset()

All those assets listed are core javascript and css assets that are normally loaded on load or on request.
When using the first function you are signaling the system that your theme will provide that asset. Say for instance you have a newer version than what's included in the core and you want to use that instead of the core.
But this doesn't mean it is loaded. It just tells the system "if this asset is requested, use mine"

When you use the second function, you are requiring an asset. This is what actually tells the system to load the asset.

Let's take a few examples
$this->providesAsset('javascript', 'bootstrap/*');
$this->providesAsset('css', 'bootstrap/*');
$this->providesAsset('css', 'blocks/form');
$this->requireAsset('css', 'font-awesome');
$this->requireAsset('javascript', 'jquery');

The first 2 lines tell the system that whenever anything bootstrap (js or css files) is requested, your theme will be provided the files

The third line tells the system that the css for the core form block will be provided by your theme. That file will be requested by the block itself anytime it is in use.

The last 2 lines tell the system to load the core font-awesome and jquery files.
ptityop replied on at Permalink Reply
THanks for taking the time to explain ... so does that mean we cannot have rquire and provide at the same time ?
And the folder structure must be the same than the one used in the core Concrete ?
How would I go if the jquery I provide is a cdn link ?
Many thanks in advance
mnakalay replied on at Permalink Reply
mnakalay
you can. You probably should.

"provides" tells the system that IF anything requires that asset it should be taken from your theme and not from anywhere else.

"require" tells the system to actually load the asset.

Like I showed in the examples above some assets are loaded when using specific blocks. Others are not and you should load them yourself.

So if you are providing an asset and you need it loaded you need to use both provide and require.

And don't worry, in the situation where more than 1 request are made for the same asset, the system is smart enough to load it only once.
mnakalay replied on at Permalink Reply
mnakalay
It doesn't seem the asset management system takes into account external resources so I am not sure you can use jquery from a cdn with the asset system.

Check it here:http://documentation.concrete5.org/developers/assets/registering-an...

Concerning core blocks, they usually use view.css files and view.js files so you might not even need to use the asset system, you probably can just override those files by putting them in application\blocks\name_of_the_block
ptityop replied on at Permalink Reply
Thanks for your help !
I must be doing something wrong still .... this does not seem to work ...
<?php 
namespace Application\Theme\Citytour;
use Concrete\Core\Area\Layout\Preset\Provider\ThemeProviderInterface;
class PageTheme extends \Concrete\Core\Page\Theme\Theme implements ThemeProviderInterface
{
    public function registerAssets()
    {
        $this->providesAsset('javascript', 'bootstrap/*');
        $this->providesAsset('css', 'bootstrap/*');
$this->providesAsset('javascript', 'js/*');
            }
    protected $pThemeGridFrameworkHandle = 'bootstrap3';
    public function getThemeName()
    {
        return t('Citytour');


If you wahnt the link to my site if it can help ... I can still see a jquery.js in the header ... I don't get it ...
citytoursbuenosaires dot com
mnakalay replied on at Permalink Reply
mnakalay
Very nice website.

Maybe you could start by telling me exactly what you are trying to achieve.

Are you trying to load your own version of jQuery? Why?
what else exactly are you trying to load that exists in the core but is different in your theme?
what else exactly are you trying to load that doesn't exist in the core and is specific to your theme?
ptityop replied on at Permalink Reply
Thank you very much :-)
As you see the site is pretty simple. What I am trying to do is to avoid loading several Jquery. But I cannot. I do not really mind wether the jquery is from the core or my own as long as they work. The same goes for the bootstrap framework I can do with the core..
I really thought this asset system would work perfectly ...
mnakalay replied on at Permalink Reply
mnakalay
The asset system works as long as it is used properly.

From what I can see, jQuery is loaded from the core AND from the cdn.

My guess is the CDN one is hard-coded in your footer. In your theme you probably have a folder labelled "elements" and inside it footer files and in one of those files a line to load jQuery from the CDN.

Now you have 2 solutions:
1- you're happy with jquery from the core so just comment out that line in your footer and add a requireasset() line in your page_theme to make sure the core loads jquery.
2- you want to load jQuery from the cdn, then add a providesasset() line so the core doesn't load it.

Same goes for bootstrap. Your theme is loading its own bootstrap css file in the header. Follow the same process as for jquery to decide which you want to load.
ptityop replied on at Permalink Reply
Hi !
I just did that and as you will see the slider does not work anymore and there is no more back to top ....
It is like any move breaks something ... nothing is straight forward...
I really appreciate your time !Thanks again !

That is mny code
[/code]
<?php
namespace Application\Theme\Citytour;

use Concrete\Core\Area\Layout\Preset\Provider\ThemeProviderInterface;

class PageTheme extends \Concrete\Core\Page\Theme\Theme implements ThemeProviderInterface
{
public function registerAssets()
{
$this->requireAsset('javascript', 'bootstrap/*');
$this->requireAsset('css', 'bootstrap/*');
$this->requireAsset('javascript', 'js/*');
$this->requireAsset('javascript', 'jquery');
}

protected $pThemeGridFrameworkHandle = 'bootstrap3';

public function getThemeName()
{
return t('Citytour');
}
[code]
Steevb replied on at Permalink Reply
Steevb
Your custom.js file is throwing an error.
mnakalay replied on at Permalink Reply
mnakalay
try just this
public function registerAssets()
{
$this->requireAsset('javascript', 'jquery'); 
}

and in your footer, uncomment the bootstrap.js line so it loads from your theme