We are near the end of the July, and the first beta release of Mys v1.3.6 is coming closer. About 2 weeks ago I managed to get PHP 7/8 compatibility working, and now I am ready to introduce another new QoL update for the new version. This one is referred to as Custom Smarty Templates, which allows users to define custom smarty templates for HTML elements. It may not be useful for absolute beginners, but will make lives significantly easier for the advanced users who are customizing the built-in view/pages from original Mysidia Adoptables script, or even building their own views/pages.
I will use an example to demonstrate what this means since the terms may sound enough confusing. For the user account index page, the html is composed programmatically with Mysidia's GUI API:
If you are already familiar with Mysidia's code, you'd notice that what this above code does is basically to compose the following HTML:
Since I am a programmer myself, the PHP code makes enough sense for me. For non-coders, they will struggle to understand what it means. The worse part is, they do not know how to create HTML elements programmatically if they want to customize the generated HTML, and will end up wrapping a long HTML string inside a text variable. With Mys v1.3.6, theres no need for such ugly workaround anymore. It is now possible to create smarty template file, which is effectively just HTML files that allow PHP variables to be safely and elegantly embeded into the file without using PHP tags.
To accomplish this, simply create a file accountlinks.tpl in folder /templates/common with the following HTML code(note $scriptPath and $mysidia are variables automatically assigned to a smarty template file so you can use the dynamic values):
And on the account view file, replace the HTML GUI code by this line which will load a template file(assuming the file accountlinks.tpl is located in /templates/common directory of your script path):
Now it will work exactly the same as the HTML GUI version, but it should look a lot easier to understand and use for non-coders. Note you may add multiple custom smarty template files for the same view/page, you can also use the HTML GUI API and Custom Smarty Templates together with each other as I've designed them to interoperate with each other. If you need to pass variables to a template file, simply use the method setField($field, $value) at the controller action(ie. index() method in account controller for this example). If you are unsure how to accomplish this, make a thread on the forum and I will explain it in a follow-up post to clear up some confusions.
Hope you all enjoy the new features introduced so far in Mys v1.3.6, I will make another 1-2 more blog post about the other QoL updates before the beta release.
I will use an example to demonstrate what this means since the terms may sound enough confusing. For the user account index page, the html is composed programmatically with Mysidia's GUI API:
PHP:
$settings = new Comment("Account Settings");
$settings->setBold();
$settings->setUnderlined();
$document->add(new Comment);
$document->add($settings);
$document->add(new Link("myadopts", "Manage Adoptables", TRUE));
$document->add(new Link("profile/view/{$mysidia->user->getID()}", "View Profile", TRUE));
$document->add(new Link("account/password", "Change Password", TRUE));
$document->add(new Link("account/email", "Change Email Address", TRUE));
$document->add(new Link("account/friends", "View and Manage FriendList", TRUE));
$document->add(new Link("account/profile", "More Profile Settings", TRUE));
$document->add(new Link("account/contacts", "Change Other Settings"));
If you are already familiar with Mysidia's code, you'd notice that what this above code does is basically to compose the following HTML:
Since I am a programmer myself, the PHP code makes enough sense for me. For non-coders, they will struggle to understand what it means. The worse part is, they do not know how to create HTML elements programmatically if they want to customize the generated HTML, and will end up wrapping a long HTML string inside a text variable. With Mys v1.3.6, theres no need for such ugly workaround anymore. It is now possible to create smarty template file, which is effectively just HTML files that allow PHP variables to be safely and elegantly embeded into the file without using PHP tags.
To accomplish this, simply create a file accountlinks.tpl in folder /templates/common with the following HTML code(note $scriptPath and $mysidia are variables automatically assigned to a smarty template file so you can use the dynamic values):
HTML:
<b>Account Settings</b>
<a href='{$scriptPath}/myadopts'>Manage Adoptables</a>
<br>
<a href='{$scriptPath}/profile/view/{$mysidia->user->getID()}'>View Profile</a>
<br>
<a href='{$scriptPath}/account/password'>Change Password</a>
<br>
<a href='{$scriptPath}/account/email'>Change Email Address</a>
<br>
<a href='{$scriptPath}/mys136b/account/friends'>View and Manage FriendList</a>
<br>
<a href='{$scriptPath}/mys136b/account/profile'>More Profile Settings</a>
<br>
<a href='{$scriptPath}/mys136b/account/contacts'>Change Other Settings</a>
And on the account view file, replace the HTML GUI code by this line which will load a template file(assuming the file accountlinks.tpl is located in /templates/common directory of your script path):
PHP:
$document->addLangvar($this->addTemplate("accountlinks"));
Now it will work exactly the same as the HTML GUI version, but it should look a lot easier to understand and use for non-coders. Note you may add multiple custom smarty template files for the same view/page, you can also use the HTML GUI API and Custom Smarty Templates together with each other as I've designed them to interoperate with each other. If you need to pass variables to a template file, simply use the method setField($field, $value) at the controller action(ie. index() method in account controller for this example). If you are unsure how to accomplish this, make a thread on the forum and I will explain it in a follow-up post to clear up some confusions.
Hope you all enjoy the new features introduced so far in Mys v1.3.6, I will make another 1-2 more blog post about the other QoL updates before the beta release.