Page 1 of 1
Question while developing a module
Posted: Mon Nov 24, 2014 5:48 pm
by dimdim
Hi,
I have a relatively basic questions, but have not found solution in the docs, will be really thankful if you point me to where to read or look.
1. Is there a way to install (load into database) page template when installing a module? I mean, using some built-in functions and not hacking into the database directly. I am interested in _page_ template, not the module templates.
2. Same as above, but about css
3. Same as above, but about images or js files.
4. How to create a page when installing the module? And alter its content and template used?
5. Most modules uses core functions for creating forms and form fields. Is there a "nice" way to alter those functions (e.g. I want all fields to have my css classes). Sure, I can alter the functions in the class.CMSModule.php , but they will be overwritten with updates. The matter is not in _my_ module, but in third-party modules (e.g. FEU Login form).
Thank you in advance for directions!
Re: Question while developing a module
Posted: Mon Nov 24, 2014 7:15 pm
by calguy1000
1-4 There is lots of documentation in the API docs for manipulating templates, pages, and stylesheets.
5. I don't recommend you use the core functions for creating input fields. Infact IIRC they are officially deprecated. Input fields (as they are largely view related) should be created in smarty templates. The only exception to this (in CMSMS 1.x) is the $this->CreateFormStart() method.
In CMSMS 2.0 there are more smarty plugins to aide in creating forms in smarty.
Here's a hypothetical example:
action.myaction.php
Code: Select all
$smarty->assign('formstart',$this->CreateFormStart(...));
$smarty->assign('formend',$this->CreateFormEnd()); // for symmetry.
$smarty->assign('user_info',$user_info);
echo $this->ProcessTemplate('myaction.tpl');
myaction.tpl
Code: Select all
{$formstart}
<div class="row">
<label class="col-sm-3 text-right'">Your Name:</label>
<input class="col-sm-9" type="text" placeholder="Enter your name" value="{$user_info.yourname}"/>
</div>
{$formend}
Re: Question while developing a module
Posted: Mon Nov 24, 2014 7:53 pm
by dimdim
Hi Calguy,
Thanks a lot for the answer! It seems, that I am overlooking something obvious in the API docs

Could you, please, give me a bit more directions on working with templates and pages from within a module?
I was looking at, say, cms_module_SetTemplate methods and similar, but all of them seems to be working with module templates, and what I need is to install a "site-wide" template, so user may apply it to the page.
If you can point me to a module which performs such operations that would be enough - I will go through the code.
Thank you in advance!
Dmitry
Re: Question while developing a module
Posted: Mon Nov 24, 2014 8:34 pm
by calguy1000
http://apidoc.cmsmadesimple.org/
See the Template class.
This code should be pretty much all you need (untested)
Code: Select all
$template = new Template;
$template->SetInitialValues();
$template->content = file_get_contents($some_filename);
$template->save();
Creating stylesheets is similar.
Creating content pages is a bit more complicated, but not by much.
Re: Question while developing a module
Posted: Mon Nov 24, 2014 8:52 pm
by calguy1000
In CMSMS 2.0 creating templates, stylesheets, 'designs (or collections)' is a bit different. You can see the CmsLayoutTemplate class in the 2.0 API docs
Here's an excerpt from the 2.0 installer.
Code: Select all
$template = new CmsLayoutTemplate();
$template->set_name('Simplex');
$template->set_description('A HTML5 based responsive template');
$template->set_content($txt);
$template->set_type($page_template_type);
$template->set_type_dflt(TRUE);
$template->add_design($design);
$template->set_owner(1);
$template->save();
Here's an example of creating a content page:
Code: Select all
$content = new Content;
$content->SetName('Home');
$content->SetAlias(); // will auto calculate an alias from the name.
$content->SetOwner(1);
$content->SetMenuText('Home Page');
$content->SetTemplateId($template->get_id());
$content->SetParentId(-1);
$content->SetActive(TRUE);
$content->SetShowInMenu(TRUE);
$content->SetCachable(TRUE);
$content->SetDefaultContent(TRUE);
$content->SetPropertyValue('searchable',1);
$content->SetPropertyValue('design_id',$design->get_id());
$content->SetPropertyValue('content_en','<!-- some content-->');
$content->Save();
After creating a content page, YOU MAY need to rebuild the hierarchy positions (there is a method for this in contentoperations).
Re: Question while developing a module
Posted: Mon Nov 24, 2014 8:56 pm
by calguy1000
In CMSMS 2.0 Designs (or collections) contain stylesheets, and templates.
The content page needs to know the design and the template id.
So if you are adding templates, stylesheets, and content pages you first need to create a design (CmsLayoutCollection).
Re: Question while developing a module
Posted: Tue Nov 25, 2014 12:23 am
by dimdim
Thanks a lot! The template class is what I have missed. I was looking in the module methods instead...
Thank you once again!