Answers.Body: <p>This functionality is comprised of multiple components – you need to build the interface, keep track of which visitor follows which events, potentially do something with that information and change up the display depending on the current time.</p>
  <p>The first thing you should do is clear up the requirements – what happens when someone follows an event? What happens when someone clicks on &quot;attend&quot;? How are event follows attributed to people across sessions – with cookies, with a login system? Maybe all that stuff is in your head, but since you don't mention any of it it's hard to give a useful answer. And if you can't explain this feature concisely in a way that makes sense to someone unfamiliar with your project, odds are you don't fully understand the problem yourself.</p>
  <p>That said, here are a couple of pointers to get you started:</p>
  <blockquote>
  <p>On the front-end i have a list of card &quot;Events&quot; and each card has a &quot;Follow&quot; button to follow the event</p>
  </blockquote>
  <p>Outputting a button in Twig is trivial, the question is what happens when someone clicks the button? If it's only stored locally in the browser, all you need is some JavaScript to handle clicks on that button and maybe store the followed events in local storage.</p>
  <p>I assume you want to keep track of which people follow which events. First you need to determine how to identify visitors. If your visitors are logged-in Craft users, that's easy, but for anonymous sessions you need some other method (like setting a cookie).</p>
  <p>Then you need to build a <a href="https://craftcms.com/docs/3.x/extend/controllers.html" rel="nofollow noreferrer">Controller</a> with an endpoint to handle event follows. The controller can contain the logic to process and store the event followers. Once you have your controller, you can either make the button a form that posts to the controller's action URL or handle button clicks in JavaScript and call the action URL manually.</p>
  <p>Check out the <a href="https://craftcms.com/docs/3.x/extend/controllers.html" rel="nofollow noreferrer">documentation on Controllers</a> to get started.</p>
  <blockquote>
  <p>when the &quot;event&quot; time is on the word &quot;follow&quot; will be replaced with &quot;Attend&quot; after clicking the btn, if it makes sense</p>
  </blockquote>
  <p>That's easy, in your Twig template for the event page, simply check if the event is currently active (i.e. the current time is between the start and end time of the event) and display the follow or attend buttons accordingly. Of course, the real question is what happens when either button is clicked – again, this is something you have to figure out as part of gathering requirements.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-25T06:35:33.083Z
Answers.Text: Thank you for your time and explanation it was a great starting point for me to read and learn more about how things are working in the background to achieve such things.
  i'm starting reading about Controllers, Creating a Module ...etc
  so when i have a good background about it i will return to this question and post an edit.
  
  Thank you again.
Answers.UserDisplayName: Ra3d K
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-25T08:48:14.433Z
Answers.Text: @RaadKasem Glad I could help! If you do run into problems, its probably better to create a new question, it's easier to answer specific smaller questions and it helps other people find answers quicker.
Answers.UserDisplayName: MoritzLost
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-04T13:50:14.570Z
Answers.LastActivityDate: 2021-11-04T13:50:14.570Z
Answers.UserDisplayName: MoritzLost
Body: <p><strong>First of all, Please excuse  my English</strong></p>
  <p>Q: I have a section called &quot;Events&quot;
  And and has some entries</p>
  <p>On the front-end i have a list of card <strong>&quot;Events&quot;</strong> and each card has a <strong>&quot;Follow&quot;</strong> button to follow the event and when the &quot;event&quot; time is on the word <strong>&quot;follow&quot;</strong> will be replaced with <strong>&quot;Attend&quot;</strong> after clicking the btn, if it makes sense</p>
  <p>How to do that in Craft with twig?</p>
  <p>I found some references in PHP and someway understood how it works with Ajax, but never understood how it's done with Craft?</p>
  <p>The path where i put js/php and where to send action request?
  How to save event following number...etc</p>
  <p>Thank you all.</p>
  
Tags: <craft3><ajax><frontend>
Title: How to create a follow system "button" for "Event" entries?
ThreadText: # How to create a follow system "button" for "Event" entries?
  
  (Asked by: username_0 on 2021-11-03)
  
  **First of all, Please excuse my English**
  
  Q: I have a section called "Events"
  And and has some entries
  
  On the front-end i have a list of card **"Events"** and each card has a **"Follow"** button to follow the event and when the "event" time is on the word **"follow"** will be replaced with **"Attend"** after clicking the btn, if it makes sense
  
  How to do that in Craft with twig?
  
  I found some references in PHP and someway understood how it works with Ajax, but never understood how it's done with Craft?
  
  The path where i put js/php and where to send action request?
  How to save event following number...etc
  
  Thank you all.
  
  **Tags:** craft3, ajax, frontend
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-11-04. Score: 4 | Accepted answer
  
  This functionality is comprised of multiple components – you need to build the interface, keep track of which visitor follows which events, potentially do something with that information and change up the display depending on the current time.
  
  The first thing you should do is clear up the requirements – what happens when someone follows an event? What happens when someone clicks on "attend"? How are event follows attributed to people across sessions – with cookies, with a login system? Maybe all that stuff is in your head, but since you don't mention any of it it's hard to give a useful answer. And if you can't explain this feature concisely in a way that makes sense to someone unfamiliar with your project, odds are you don't fully understand the problem yourself.
  
  That said, here are a couple of pointers to get you started:
  
  > On the front-end i have a list of card "Events" and each card has a "Follow" button to follow the event
  
  Outputting a button in Twig is trivial, the question is what happens when someone clicks the button? If it's only stored locally in the browser, all you need is some JavaScript to handle clicks on that button and maybe store the followed events in local storage.
  
  I assume you want to keep track of which people follow which events. First you need to determine how to identify visitors. If your visitors are logged-in Craft users, that's easy, but for anonymous sessions you need some other method (like setting a cookie).
  
  Then you need to build a [Controller](https://craftcms.com/docs/3.x/extend/controllers.html) with an endpoint to handle event follows. The controller can contain the logic to process and store the event followers. Once you have your controller, you can either make the button a form that posts to the controller's action URL or handle button clicks in JavaScript and call the action URL manually.
  
  Check out the [documentation on Controllers](https://craftcms.com/docs/3.x/extend/controllers.html) to get started.
  
  > when the "event" time is on the word "follow" will be replaced with "Attend" after clicking the btn, if it makes sense
  
  That's easy, in your Twig template for the event page, simply check if the event is currently active (i.e. the current time is between the start and end time of the event) and display the follow or attend buttons accordingly. Of course, the real question is what happens when either button is clicked – again, this is something you have to figure out as part of gathering requirements.
  
  > **Comments:**
  > **username_0**: Thank you for your time and explanation it was a great starting point for me to read and learn more about how things are working in the background to achieve such things. i'm starting reading about Controllers, Creating a Module ...etc so when i have a good background about it i will return to this question and post an edit.  Thank you again.  
  > **username_1**: @RaadKasem Glad I could help! If you do run into problems, its probably better to create a new question, it's easier to answer specific smaller questions and it helps other people find answers quicker.  
  
  ---
  
  