Jump to content
Pavle

Ideas for link/button Fieldtype/Inputtype

Recommended Posts

Hello all,

I am thinking how to make a "simple" button that could be edited by user.

For example in a situation where we have an editable teaser and we want to add a internal link to some other page under it.

The button/link would take two parameters:

1.) Text that is displayed on a button (in different languages!)

2.) Page to which button would link to.

3.) Optional: instead of page object, one could also enter external address.

System admin should also be able to add class name that would be added to rendered element.

Field would then simply be used as: $page->button and it would render <a class='custom-class' href="$page->url">Text (in appropriate language)</a>

I noticed it is sort of similar to this module, but with an option for user to select one of the pages (instead of writing down an ID).

My first thoughts were to create Fieldtype/Inputtype module, but it seems sort of complicated (I don't know how to use neither FieldtypeTextLanguage nor FieldtypePage in module).

So I wonder, how you guys are solving this problem?

Thanks!

Žiga

PS.

I am not sure I added this to the right section. If not, please feel free to move it where it's suppose to be.

Share this post


Link to post
Share on other sites

If you want your editors to be able to insert the button in a textarea field, your simplest option might be a Hanna code so your editors could do something like:

[[button label="Click Here" link="http://www.mysite.com/mypage"]]

Otherwise you could have a button created to an internal page by providing them with a Pagefield called "linked_page" and set the input field type to PageListSelect+

Then in your template file use the following code:

echo "<a href='{$page->linked_page->url}' class='button'>Default Button</a>";
  • Like 3

Share this post


Link to post
Share on other sites

Hey Adrian,

Thanks for such a fast reply! Your solution would work perfectly if I would have only one language OR if editors would be either linking to external pages or they would remember all page-names, but I fear this approach is (in my case) prone to mistakes/errors.

Using:

Fieldset

TextLanguage

Page

Fieldset_END

 

...would actually do everything that I need, it's just that every time I would want to add a link/button to a template I would need to add all this 4 fields, so I was hoping there is an easy solution for combining different fields into a new Fieldtype.

It would be perfect if there would be something like a module for creating custom Fieldtypes, where one would just create/select needed fields (something like creating a page template, but with the ability to create fields on-the-go) and set output (html) and module would generate appropriate Fieldtype and Inputtype based on that.

Or it would be great if there would be a Fieldtype similar to repeater, just without the ability to repeat...so in the way of selectable Fieldset (fields group)...basically if Fieldset could be added to page template in the similar way than repeater :)

post-2420-0-24685100-1410357136_thumb.jp

Share this post


Link to post
Share on other sites

You could simply write a small php script, which includes all those fields to selected templates via the api. Only rearranging would be manual work.

Share this post


Link to post
Share on other sites

You could simply write a small php script, which includes all those fields to selected templates via the api. Only rearranging would be manual work.

Thanks for this tip. I never thought of that.

Plus, unfortunately, I am not that good with php. Could you maybe explain a bit more, how this could be done? :)

Share this post


Link to post
Share on other sites

Sorry - I didn't your original post completely and so missed the multilanguage issues.

Ignoring the option for an external address for the moment, using the Pagefield approach would allow this:

echo "<a href='{$page->linked_page->url}' class='button'>{$page->linked_page->title}</a>";

I don't know much about multilanguage things, but wouldn't that use the title for the currently selected language on the front-end?

Back to the custom external address option - given the multilanguage needs, perhaps the new PageTable field (in the dev version of PW which will be released as stable 2.5 in the next week) could help you out - could you make use of a multilanguage title field and a url field.

Maybe a simpler approach since I think you only want one button per page would be to use a Pagefield with the PageListSelect+ option, but if that is left blank, provide a text url field so they can enter an external link. Then for the button labels you could use a textarea field like this:

english: Link

spanish: Viniculo

etc

Then you could parse the textarea for the appropriate language and display that on the button.

Another possibility might be the Multiplier field (also linked from the PageTable field link above) and use that to add a label for each language.

Lots of options - maybe see if one of them sounds good to you and we can help you implement it.

Share this post


Link to post
Share on other sites

@Pavle 

Haven't checked if it works, but it should get you going.

Edit: Please look at Soma's post: https://processwire.com/talk/topic/7544-ideas-for-linkbutton-fieldtypeinputtype/#entry72694

	$templates = array();
	$templates[] = $templates->get("templateName1");
	$templates[] = $templates->get("templateName2");
	$templates[] = $templates->get("templateName3");
	$templates[] = $templates->get("templateName4");

	foreach($templates as $template){
		$template->fields->add("fieldset"); //use the fieldnames
		$template->fields->add("text_language");
		$template->fields->add("page");
		$template->fields->add("fieldset_END");

		$template->save();
	}

Share this post


Link to post
Share on other sites

I find it strange that a CMS has no link (or link list) feature. After all it's about links. I also would be many times in need for a repeater style slick link field. 

Thing is it can get really tricky really fast to build such a module especially if you need to be able to either enter url, select a internal page, have attributes like open in new window etc. Then maybe need something to enter linktext (also multilanguage), and then maybe even the urls should be different for each language. 

I solved it with either

- repeater

- just have them make the list in wysywg

- markdown textarea (kinda hard for clients)

If I'm lucky and there's only one link required, I solved it using a text language field, a page reference, and a url field. And handle it on template output.

Maybe we can sponsor a link (list) tool.

Share this post


Link to post
Share on other sites

@Pavle 

Haven't checked if it works, but it should get you going.

	$templates = array();
	$templates[] = $templates->get("templateName1");
	$templates[] = $templates->get("templateName2");
	$templates[] = $templates->get("templateName3");
	$templates[] = $templates->get("templateName4");

	foreach($templates as $template){
		$template->fields->add("fieldset"); //use the fieldnames
		$template->fields->add("text_language");
		$template->fields->add("page");
		$template->fields->add("fieldset_END");

		$template->save();
	}

I'm not sure what that should be for solving the problem. :)

Anyway before it gets out of hand. 

$templates is a template system variable, you empty it on first line...

If then you could do such a task like:

$tpls = $templates->find("name=basic-page|sitemap");
foreach($tpls as $t){
    $t->fields->add("myfield");
    ...
}

You can also do this

$t = $templates->get("basic-page");
$t->fields->insertBefore( $fields->myfield1, $t->fields->images );
$t->fields->insertAfter( $fields->myfield2, $t->fields->images );
$t->fields->save();

Share this post


Link to post
Share on other sites

Using:

Fieldset

TextLanguage

Page

Fieldset_END

 

...would actually do everything that I need, it's just that every time I would want to add a link/button to a template I would need to add all this 4 fields, so I was hoping there is an easy solution for combining different fields into a new Fieldtype.

My code was an example so do this by the api. The $templates variable was so conveniently named , as said didn't tested it :)

Share this post


Link to post
Share on other sites

Sorry, I was away yesterday :)

@ LostKobrakai

Of course! I completely forgot all about $template object and the whole fact that one can also manipulate templates like that :)

@ Soma & Adriam

Yeah, I have only one link per page, so I think that I will go with Soma's solution at the end (which is, I guess, what Adrian proposed as well :)

If I'm lucky and there's only one link required, I solved it using a text language field, a page reference, and a url field. And handle it on template output.

I know this post is sort of complicating about little things, but I agree with Soma...I was expecting it would be more elegant at the end (as most of other stuff in PW are).

I am not really an expert in module building (not even an advance builder :) but I notices some other modules are doing similar stuff. For example PWlink for CKEditor has options to Link to URL, Link to Page, Link to File, Open in New window.

The most interesting example module for "fieldtype building module" would be Repeater, without the repeating part. I checked it yesterday and it seems quite complicated, but as far as I understood the repeater field (that we include in the template) is actually a page (template) with all this other fields. I like the fact that we don't actually see those pages anywhere (like we do with the new PageTable field). I mean...i don't know I would imagine some of my clients would be a bit confused when they would see "link1", "link2" subpages (yeah, I have some interesting clients :)  

Share this post


Link to post
Share on other sites
I like the fact that we don't actually see those pages anywhere (like we do with the new PageTable field). I mean...i don't know I would imagine some of my clients would be a bit confused when they would see "link1", "link2" subpages (yeah, I have some interesting clients

I wouldn't blame your clients on this one - whenever I use the PageTable field I always use the "Select a parent for items" and use a hidden parent page that clients won't look in. I think using the default parent is very messy. I think PageTable is much cleaner than repeaters for lots of reasons and now with PageTableExtended, it's even better.

Share this post


Link to post
Share on other sites

@adrian

A bit late, but yeah, you are absolutely right. I completely forgot about all additional options with page select. At the end, I used multiple fields wrapped in filedset...anyway I realized that I can just duplicate fields from other template, if I need buttons on multiple pages (templates).

Thank you all for your help!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By joshua
      This module is (yet another) way for implementing a cookie management solution.
      Of course there are several other possibilities:
      - https://processwire.com/talk/topic/22920-klaro-cookie-consent-manager/
      - https://github.com/webmanufaktur/CookieManagementBanner
      - https://github.com/johannesdachsel/cookiemonster
      - https://www.oiljs.org/
      - ... and so on ...
      In this module you can configure which kind of cookie categories you want to manage:

      You can also enable the support for respecting the Do-Not-Track (DNT) header to don't annoy users, who already decided for all their browsing experience.
      Currently there are four possible cookie groups:
      - Necessary (always enabled)
      - Statistics
      - Marketing
      - External Media
      All groups can be renamed, so feel free to use other cookie group names. I just haven't found a way to implement a "repeater like" field as configurable module field ...
      When you want to load specific scripts ( like Google Analytics, Google Maps, ...) only after the user's content to this specific category of cookies, just use the following script syntax:
      <script type="optin" data-type="text/javascript" data-category="statistics" data-src="/path/to/your/statistic/script.js"></script> <script type="optin" data-type="text/javascript" data-category="marketing" data-src="/path/to/your/mareketing/script.js"></script> <script type="optin" data-type="text/javascript" data-category="external_media" data-src="/path/to/your/external-media/script.js"></script> <script type="optin" data-type="text/javascript" data-category="marketing">console.log("Inline scripts are also working!");</script> The type has to be "optin" to get recognized by PrivacyWire, the data-attributes are giving hints, how the script shall be loaded, if the data-category is within the cookie consents of the user. These scripts are loaded asynchronously after the user made the decision.
      If you want to give the users the possibility to change their consent, you can use the following Textformatter:
      [[privacywire-choose-cookies]] It's planned to add also other Textformatters to opt-out of specific cookie groups or delete the whole consent cookie.
      You can also add a custom link to output the banner again with a link / button with following class:
      <a href="#" class="privacywire-show-options">Show Cookie Options</a> <button class="privacywire-show-options">Show Cookie Options</button> This module is still in development, but we already use it on several production websites.
      You find it here: PrivacyWire Git Repo
      Download as .zip
      I would love to hear your feedback 🙂
      CHANGELOG
      0.0.5 Multi-language support included completely (also in TextFormatter). Added possibility to async load other assets (e.g. <img type="optin" data-category="marketing" data-src="https://via.placeholder.com/300x300">) 0.0.4 Added possibility to add an imprint link to the banner 0.0.3 Multi-language support for module config (still in development) 0.0.2 First release 0.0.1 Early development
    • By MoritzLost
      This is a new module that provides a simple solution to clearing all your cache layers at once, and an extensible interface to perform various cache-related actions.
      The simple motivation behind this module was that I was tired of manually clearing caches in several places after deploying a change on a live site. The basic purpose of this module is a simple Clear all caches link in the Setup menu which clears out all caches, no matter where they hide. You can customize what exactly the module does through it's configuration menu:
      Expire or delete all cache entries in the database, or selectively clear caches by namespace ($cache API) Clear the the template render cache. Clear out specific folders inside your site's cache directory (/site/assets/cache) Refresh version strings for static assets to bust client-side browser caches (this requires some setup, see the full documentation for details). This is the basic function of the module. However, you can also add different cache management action through the API and execute them through the module's interface. For this advanced usage, the module provides:
      An interface to see all available cache actions and execute them. A system log and logging output on the module page to see verify what the module is doing. A CacheControlTools class with utility functions to clear out different caches. An API to add cache actions, execute them programmatically and even modify the default action. Permission management, allowing you granular control over which user roles can execute which actions. The complete documentation can be found in the module's README.
      Beta release
      Note that I consider this a Beta release. Since the module is relatively aggressive in deleting some caches, I would advise you to install in on a test environment before using it on a live site.
      Let me know if you're getting any errors, have trouble using the module or if you have suggestions for improvement!
      In particular, can someone let me know if this module causes any problems with the ProCache module? I don't own or use it, so I can't check. As far as I can tell, ProCache uses a folder inside the cache directory to cache static pages, so my module should be able to clear the ProCache site cache as well, I'd appreciate it if someone can test that for me.
      Future plans
      If there is some interest in this, I plan to expand this to a more general cache management solution. I particular, I would like to add additional cache actions. Some ideas that came to mind:
      Warming up the template render cache for publicly accessible pages. Removing all active user sessions. Let me know if you have more suggestions!
      Links
      https://github.com/MoritzLost/ProcessCacheControl ProcessCacheControl in the Module directory

    • By David Karich
      Admin Page Tree Multiple Sorting
      ClassName: ProcessPageListMultipleSorting
      Extend the ordinary sort of children of a template in the admin page tree with multiple properties. For each template, you can define your own rule. Write each template (template-name) in a row, followed by a colon and then the additional field names for sorting.
      Example: All children of the template "blog" to be sorted in descending order according to the date of creation, then descending by modification date, and then by title. Type:
      blog: -created, -modified, title  Installation
      Copy the files for this module to /site/modules/ProcessPageListMultipleSorting/ In admin: Modules > Check for new modules. Install Module "Admin Page Tree Multible Sorting". Alternative in ProcessWire 2.4+
      Login to ProcessWire backend and go to Modules Click tab "New" and enter Module Class Name: "ProcessPageListMultipleSorting" Click "Download and Install"   Compatibility   I have currently tested the module only under PW 2.6+, but think that it works on older versions too. Maybe someone can give a feedback.     Download   PW-Repo: http://modules.processwire.com/modules/process-page-list-multiple-sorting/ GitHub: https://github.com/FlipZoomMedia/Processwire-ProcessPageListMultipleSorting     I hope someone can use the module. Have fun and best regards, David
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version (has been tested up to v3.3), add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "https://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


×
×
  • Create New...