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!
Question while developing a module
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: Question while developing a module
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
myaction.tpl
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');
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}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Re: Question while developing a module
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
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
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: Question while developing a module
http://apidoc.cmsmadesimple.org/
See the Template class.
This code should be pretty much all you need (untested)
Creating stylesheets is similar.
Creating content pages is a bit more complicated, but not by much.
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 content pages is a bit more complicated, but not by much.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: Question while developing a module
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.
Here's an example of creating a content page:
After creating a content page, YOU MAY need to rebuild the hierarchy positions (there is a method for this in contentoperations).
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();
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();
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: Question while developing a module
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).
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).
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Re: Question while developing a module
Thanks a lot! The template class is what I have missed. I was looking in the module methods instead...
Thank you once again!
Thank you once again!