Jump to content

Gayan Virajith

Members
  • Posts

    58
  • Joined

  • Last visited

Everything posted by Gayan Virajith

  1. Thank you so much apesia, soma and adrian. @soma and @apeisa - I followed your advise. Thanks again now it is working fine (happy). @adrian - Yes adrian I put news-pager-index.php file under template directory. Just to recap: if we need use external template file other than the template name we have to use altFilename property. In the normal scenario we can use name property if the template file name and template name were same. Here is the working copy thanks to processwire and friendly community members. It might be helpful to newbies like me. class NewsPager extends WireData implements Module{ public static function getModuleInfo() { return array( 'title' => 'News pager', 'version' => 001, 'summary' => 'News pager template', 'singular' => true, 'autoload' => true, ); } public function init() { //todo add some listeners } /** * Install the module * */ public function ___install() { // new fieldgroup $fg = new Fieldgroup(); $fg->name = 'news-pager-index'; $fg->add($this->fields->get('title')); // needed title field $fg->add($this->fields->get('body')); // needed body field $fg->save(); // new template using the fieldgroup and a template $t = new Template(); $t->name = 'news-pager-index';//Used different name other than file name /* * altFilename property will accept file-name or file-name.php * or even $this->config->paths->templates . 'file-name.php' * Note: template file needs to be placed under * template directory */ $t->altFilename = 'news-pager-index-file';//name of the template file which is under tml dir. $t->fieldgroup = $fg; // add the field group $t->save(); } /** * Uninstall the module * */ public function ___uninstall() { $templateNeeded = $this->templates->get("news-pager-index"); $fgOld = $this->fieldgroups->get('news-pager-index'); if ($templateNeeded->getNumPages() > 0) { throw new WireException("Can't uninstall because template been used by some pages."); }else { wire('templates')->delete($templateNeeded); wire('fieldgroups')->delete($fgOld); } } }
  2. Hi, Thanks again for great CMS. I was trying to create a module that can create a new template file and fields. Here is my module script: class NewsPager extends WireData implements Module{ public static function getModuleInfo() { return array( 'title' => 'News pager', 'version' => 001, 'summary' => 'News pager testing!', 'singular' => true, 'autoload' => true, ); } public function init() { //todo add some listeners } /** * Install the module * */ public function ___install() { // new fieldgroup $fg = new Fieldgroup(); $fg->name = 'new-template9'; $fg->add($this->fields->get('title')); // needed title field $fg->add($this->fields->get('body')); // needed title field $fg->save(); // new template using the fieldgroup $t = new Template(); $t->name = 'new-template9'; $t->filename=$this->config->paths->templates . 'news-pager-index.php'; $t->fieldgroup = $fg; // add the fieldgroup $t->save(); } /** * Uninstall the module * */ public function ___uninstall() { $templateNeeded = $this->templates->get("new-template9"); if ($templateNeeded->getNumPages() > 0) { throw new WireException("Can't uninstall because template been used by some pages."); }else { wire('templates')->delete($templateNeeded); } } } The module works fine. But when I try to create pages by using newly created template, in that case the view link is not appearing. Is there any property that I should use for template creation to get view link to be worked. Thank you
  3. Thanks Soma and RJay. This would be my module script: class SiteSettings extends WireData implements Module, ConfigurableModule { public static function getModuleInfo() { return array( 'title' => 'Site settings', 'version' => 0.01, 'summary' => 'Store general site settings', 'author' => 'Gayan Virajith', 'singular' => true, 'autoload' => true, ); } static public function getDefaultData() { return array( 'siteLogo' => '', ); } public function __construct() { foreach(self::getDefaultData() as $key => $value) { $this->$key = $value; } } public function init() { //do it later } public static function getModuleConfigInputfields(array $data) { $inputfields = new InputfieldWrapper(); // ask site logo image $field = wire('modules')->get('InputfieldImage'); $field->name = 'siteLogo'; $field->label = "Site Logo"; $field->maxFiles = 1; if(isset($data['siteLogo'])) $field->value = $data['siteLogo']; $inputfields->add($field); return $inputfields; } } I have attached module preview as well. According to Soma's advise, I have to give up. Thanks every one.
  4. Hello Processwire, First of all thank you for a wonderful CMS. This would be my first question to the Processwire community as I started with it. I am trying to create module which can keep site logo as a configurable input field. I use following code to create InputFieldImage and still no luck. public static function getModuleConfigInputfields(array $data) { $field = wire('modules')->get('InputfieldImage'); $field->name = 'siteLogo'; $field->label = "Site Logo"; $field->maxFiles = 1; if(isset($data['siteLogo'])) $field->value = $data['siteLogo']; $inputfields->add($field); return $inputfields; } Any advise will be greatly appreciated. Thanks again.
×
×
  • Create New...