sam13579 Posted November 14, 2021 Posted November 14, 2021 I was looking for code sample where I can attach a textarea for setting up a content in my page. And I wanted to do it programatically. But I can't find a way to do that. Is it possible to add a content textarea with program?
pwired Posted November 15, 2021 Posted November 15, 2021 Quote Is it possible to add a content textarea with program? Have you seen the processwire documentation ? https://processwire.com/api/ref/field/ 1) Setup a field of type textarea 2) Echo or include the textarea field where you want it echo $Yourpage->yourfield; include $Yourpage->yourfield; 1
sam13579 Posted November 15, 2021 Author Posted November 15, 2021 8 hours ago, pwired said: Have you seen the processwire documentation ? https://processwire.com/api/ref/field/ 1) Setup a field of type textarea 2) Echo or include the textarea field where you want it echo $Yourpage->yourfield; include $Yourpage->yourfield; And how to create "yourfield" with program?
sam13579 Posted November 15, 2021 Author Posted November 15, 2021 8 hours ago, pwired said: Have you seen the processwire documentation ? https://processwire.com/api/ref/field/ 1) Setup a field of type textarea 2) Echo or include the textarea field where you want it echo $Yourpage->yourfield; include $Yourpage->yourfield; I was looking for a way to make template with fields programatically. But I think this is not happening. What you are suggesting is adding fields that are already made inside database. But thanks.
pwired Posted November 15, 2021 Posted November 15, 2021 I was addressing your first question This is a different question Quote I was looking for a way to make template with fields programatically. Have you read the Processwire Documentation ? Your answers are here: https://processwire.com/docs/start/variables/templates/ --------------------------------------------------------------------- Creating a new template with api <?php namespace ProcessWire; $fieldgroup = new Fieldgroup(); $fieldgroup->name = "something"; $fieldgroup->add("title"); // add some fields $fieldgroup->add("body"); $fieldgroup->add("summary"); $fieldgroup->save(); $template = new Template(); $template->name = "something"; // must be same name as the fieldgroup $template->fieldgroup = $fieldgroup; $template->save(); --------------------------------------------------------------------- Adding fields to a template with api <?php namespace ProcessWire; $template = $templates->get("some_template"); $template->fields->add("body"); // add some fields $template->fields->add("summary"); $template->fields->add("images"); $template->fields->save(); --------------------------------------------------------------------- Forumhttps://processwire.com/talk/topic/4921-how-to-create-template-file-using-api-under-a-module/https://processwire.com/talk/topic/352-creating-pages-via-api/ Exampleshttps://processwire-recipes.com/recipes/add-fields-to-template/ Beginner mistakeshttps://processwire.com/talk/topic/19415-trying-to-create-field-using-api/ 3 1
sam13579 Posted November 15, 2021 Author Posted November 15, 2021 1 hour ago, pwired said: I was addressing your first question This is a different question Have you read the Processwire Documentation ? Your answers are here: https://processwire.com/docs/start/variables/templates/ --------------------------------------------------------------------- Creating a new template with api <?php namespace ProcessWire; $fieldgroup = new Fieldgroup(); $fieldgroup->name = "something"; $fieldgroup->add("title"); // add some fields $fieldgroup->add("body"); $fieldgroup->add("summary"); $fieldgroup->save(); $template = new Template(); $template->name = "something"; // must be same name as the fieldgroup $template->fieldgroup = $fieldgroup; $template->save(); --------------------------------------------------------------------- Adding fields to a template with api <?php namespace ProcessWire; $template = $templates->get("some_template"); $template->fields->add("body"); // add some fields $template->fields->add("summary"); $template->fields->add("images"); $template->fields->save(); --------------------------------------------------------------------- Forumhttps://processwire.com/talk/topic/4921-how-to-create-template-file-using-api-under-a-module/https://processwire.com/talk/topic/352-creating-pages-via-api/ Exampleshttps://processwire-recipes.com/recipes/add-fields-to-template/ Beginner mistakeshttps://processwire.com/talk/topic/19415-trying-to-create-field-using-api/ That saved my day. Thanks.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now