Jump to content

Search- and Front-End-Login-Function in Twig


AndZyk
 Share

Recommended Posts

Dear ProcessWire-Community,

first of all I want to apologize for my weak english. I'm german and will try my best, but I hope you can forgive me if I missspell something or can't explain it in the right way.

Further I want to point out, that in the last few weeks I've become a big fan of the ProcessWire CMS. The free structure with no useless functions and the great community made this CMS to one of my favourite CMSs. And that's the reason why I would like to ask for your help.

I'm developing right now an medium-sized website and for this website I'm using the Template Twig Replace-Module. This module is great for saving lots of PHP-syntax, but is also very strict when you code wrong. For this website I want to implement an search and front-end-login-function and even though there are great tutorials for those functions available in PHP, I don't know how to translate those functions into the Twig-syntax.

For the front-end-login-function I would like to try out this script.

And for the search-function I would like to use the function from the search.php-template file, which is available when you first download ProcessWire.

Now here is my question: Would somebody of you like to help me translate those functions into the Twig-Syntax or could someone explain to me how to use PHP-functions within the Template Twig Replace-Module.

I know this is a lot to ask for and that this is a ProcessWire-forum and not a Twig-forum, but you would help me a lot.

Sincerely, Andreas

Link to comment
Share on other sites

First of all: Welcome to the world of PW =)

Second: no worries about spelling and grammar. There so many people on here who are not native English speakers and a lot of posts full of broken English ;D We still understand each other.

Regarding your question:

I can't help you with that, because I am not proficient enough with Twig yet. What my opinion on your way of wanting to do things is that you rather should exclude as much logic from the Twig templates as possible. I would not recommend implementing search logic into a Twig template.

As far as I know the TwigReplace module alone might not be optimal, use the DataProviders module by the same author to seperate the concerns of logic and rendering. Or use Twig separately to just render out the data you prepared with PHP beforehand. Only use some conditional statements, loops, variables and string modifiers.

Well, that's how I see things =)

Link to comment
Share on other sites

Hello owizm,

thank you for your fast response and your warm welcome.

I see that you are german too, so I don't have concerns that we don't understand each other. :D

I also thought to myself that I shouldn't implement more complex functions into the Twig templates.

But I didn't knew about the Template Data Providers-Module, so thank you for that tipp.

I'm gonna try this module now and report if I had success with it.

My alternatives would be to call the PHP-function in an separate file and then redirect and output my results to the template file.

The last thing would be to get rid of the Template Twig Replace-Module and use PHP for the hole template again, but I like twig and find it very comfortable to output fields.

I'll keep you updated and have a nice day.

Greetings, Andreas

Link to comment
Share on other sites

Hey everyone it's me again,

so yesterday I found a solution for my problem with implementing a search- and front-end-login-function into my twig templates.

Neither did I had to use the Template Data Providers-Module nor an extra PHP-Template just for the function.

I just simply translated the two exisitng functions barely into the Twig-syntax.

It wasn't that difficult after all, I was just confused on friday, when I posted this entry.

If someone is interested in my code, I can post it here for everyone. Just ask and I'll do it.

My functions aren't perfect yet, for example I currenty don't use the whitelist or sanitizing, but they work and that's a start for me.

So for any questions on this topic I'm still available. Have a nice day.

Greetings, Andreas

Link to comment
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
 Share

×
×
  • Create New...