Single Pages in Packages

I’m trying to create a package with a custom single_page. I’ve been frustrated with the documentation for reasons I’ll resist ranting about here - but I’m hoping someone can help sort me out.

Files/paths from packages\my_package

├───themes
│   └───theme_my_package
├───install
│   └ single_pages.xml
├───single_pages
│   └───card
│       └ view.php
└───controllers
    └───single_page
        └───card
            └ card.php

I cannot find a good example of using CIF for single_pages in packages, but here’s what I’ve been using in single_pages.xml:

<?xml version="1.0"?>
<concrete5-cif version="1.0">
  <singlepages>
      <page name="View Card" path="/card" description="View card" package="my_package" global="true" filename="/card/card.php" pagetype="" />
  </singlepages>
</concrete5-cif>

This is indeed installing the single page and the view.php is working - but the controller doesn’t seem to be working since when I do

$this->set(‘keyname’,$value)

in the controller’s view function, $keyname is not available within the view; nor have I been able to get other view functions to work at all (always just giving 404s).

Where do I put the controller for a packaged single_page, and how do I reference it correctly in the CIF install file?

If I’m not mistaken, given how you set up your files, your path is not /card but card/card so your xml file is attributing the wrong URL to the page. That’s probably why it can’t find the controller.
If you want to keep the path /card your controller should be in controllers\single_page\card.php and your single page should be single_pages\card.php although keeping it like you have it single_pages\card\view.php will probably work as well.

Thanks for the reply @mnakalay I’m not sure I understand, however.

Do you know of any documentation on what the “filename=” attribute is actually supposed to point to for a single_pages CIF install in a package? (And if the path is relative, from what assumed install point etc?)

I’ve tried several path structures, and I believe the current one most correctly matches the documentation (though admittedly the documentation jumps all over the place as to if the single_page is in a package or not, and never actually provides a CIF example for packages).

I believe the path= attribute is the path of the single_page as listed in the dashboard. I assumed the filename= attribute was meant to be for the controller (and the documentation insists the controller should be in the controllers\single_page\page_name\ path) … but I just can’t get the controller views or $this->set() to work.

I don’t know if there’s documentation for that but looking at what concrete itself is doing, filename should be the relative path for the single page, not for the controller.
So in your case it should be /card/view.php and not /card/card.php

As for the controller, let’s take the dashboard page as an example.
The single page is single_pages/dashboard/view.php but the controller is controllers/single_page/dashboard.php and not inside a dashboard folder.

With that in mind, your xml should be

<?xml version="1.0"?>
<concrete5-cif version="1.0">
  <singlepages>
      <page name="View Card" path="/card" description="View card" package="my_package" global="true" filename="/card/view.php" pagetype="" />
  </singlepages>
</concrete5-cif>

And your file structure should be


├───themes
│   └───theme_my_package
├───install
│   └ single_pages.xml
├───single_pages
│   └───card
│       └ view.php
└───controllers
    └───single_page
        └───card.php

If you want to see more examples of how Concrete installs single pages, look inside concrete/config/install/base/single_pages

Oh, one last thing, once an erroneous single page has been installed, it can’t be difficult to correct things. First, you’ll have to make sure the single page in uninstalled before trying to install it again. Second, you might have to go through the database and manually remove references to the path. I know I had this problem in the past where my controller was not where it was supposed to be, and it couldn’t get uninstalled properly before reinstalling, so the wrong reference still applied and things didn’t work.

Sadly that doesn’t appear to be it.
My path now matches your proposed layout, but with the same effect. The uninstall/reinstall appears to be removing it appropriately.

If you want to see more examples of how Concrete installs single pages, look inside concrete/config/install/base/single_pages

Yes, that’s where I got the CIF syntax I have now (it’s not given in the documentation) - but again those paths/etc are all working on the assumption of some other base install path.

I have looked for other (free) custom packages to reference but so far, none of the ones I’ve found have used CIFs for Single Pages (and most are from older versions of Concrete).

What mnakalay said.

Also be sure, that your controller in:
packages/my_package/controllers/single_page/card.php
has proper namespace set:

namespace Concrete\Package\MyPackage\Controller\SinglePage;

View file should be placed in:
packages/my_package/single_pages/card/view.php

Remember to replace “my_package”/“MyPackage” with your actual package name.

Filename in .xml file will be always relative to “single_pages” folder.
“package=“my_package”” will force looking for view file in “my_package” folder.
Don’t use dashes (-) in path, only underscores (_) work.

If this still doesn’t help, I can post/send you working example later.

Thanks @Parasek

namespace Concrete\Package\MyPackage\Controller\SinglePage;

Shouldn’t that be:

namespace Concrete\Package\MyPackage\Controller\SinglePage\Card;

Also thanks for the details on filename, but for clarity: should it point to the default view file or the controller? It seems to be able to find the view file just fine even without the filename= attribute.

It should be

namespace Concrete\Package\MyPackage\Controller\SinglePage;

“Card” part should go as class name of packages/my_package/controllers/single_page/card.php:

class Card extends PageController

It should point to view file. View file is necessary to create single page and controller is optional, as far as I remember.

Ooooh! It looks like it found the controller! I’m able to use $this->set() now.

The primary problem in the end (though over time there may have been several hashed out here) appears to have been my namespace in the controller file.

I’ll play with the controller more and report back, but at the moment it seems to be working.

Thanks to all for the help @Parasek , @mnakalay

1 Like

Good teamwork @Parasek @Davo :smile:

2 Likes

I’ve tried several path structures, and I believe the current one most correctly matches the documentation (though admittedly the documentation jumps all over the place as to if the single_page is in a package or not, and never actually provides a CIF example for packages).

I’ll play with the controller more and report back, but at the moment it seems to be working..