Comments (9)
It works! Thanks.
from twill.
Hi @wratke!
I see 3 possibles approaches there, depending on the number of pages you'll need and their forms compositions:
-
A single
pages
module, with all fields and relationships in the same Eloquent model. This can seem ugly, but the simplest way to implement if you don't have tons of pages with very different fields. In the form's Blade file, you can include a different file depending on a type you store in pages records (seeded upfront or created through the UI, with a dropdown to chose type inside the Add new modal, which you can add by overwritingcreate.blade.php
in your module views). -
One module per page, which means a single record in each associated table, and no listing in the CMS, but direct access to the form through the navigation, by using a route name in
twill-navigation.php
instead of'module' => true
. This is working great for say big landing pages that requires a lot of copy fields, browsers, repeaters and so on. Approach 1 becomes quickly messy in those instances. -
A single
pages
module, with all fields saved in a JSON column. This would require some custom logic in your module's repository, but this is definitely possible. My comment about page's type in 1. also apply here.
Most of the time for us at AREA 17, projects use a combination of 1 and 2, as well as a "generic" page model where all records share the same form but users are benefiting from the block editor to create any composition on those.
from twill.
Thanks, this is helpful. Is it possible to use a route that points directly to a specific record in the database in the twill-navigation.php
file? Say I create a module for a page and created a single record (which had an id of 1). Could I create a route that links directly to the edit page for that specific record using it's id?
from twill.
You could do it using the id, yes, by using the 'raw'
option in a navigation entry:
'page' => [
'raw' => true,
'route' => /pages/1/edit
]
However, you can also register a custom route for it:
Route::module('pages');
Route::name('homepage')->get('homepage', 'PageController@homepage');
Then, in the pages
module controller:
public function homepage()
{
// find the page by type or anything you've decided to use to differentiate them
abort_unless($page = Page::whereType('homepage')->first(), 500, 'Homepage missing');
// this is so that Twill always goes back to that form's route directly, not pages listing
Session::put("pages_back_link", route('admin.homepage'));
// with this approach you can provide your own view for each page
return view('admin.pages.homepage', $this->form($page->id));
}
from twill.
Great, thanks!
from twill.
One quick question. Is it possible to access the data that populates the form in the blade template? Is that data accessible as a PHP variable ? I can see how to create conditional logic in the blade template in the Laravel docs, but I need to get a sense of how Twill handles the data behind the scenes before I can do that.
from twill.
I'm talking specifically about the form.blade.php template generated for a module. If I have a field in the database called type
, I'm trying to figure out how to access that data from whatever Twill is doing when it populates the form in the template.
from twill.
You should be able to access the edited model using the $item
variable in Blade.
from twill.
- One module per page, which means a single record in each associated table, and no listing in the CMS, but direct access to the form through the navigation, by using a route name in
twill-navigation.php
instead of'module' => true
. This is working great for say big landing pages that requires a lot of copy fields, browsers, repeaters and so on. Approach 1 becomes quickly messy in those instances.
Hi @ifox
I've been trying to wrap my head around how you create single pages in Twill. The above method sounds like the most logical in many cases when you want to keep your pages as separate from each other as possible. I just have a hard time figuring out what is the so to speak 'best practice' to go about it. I am new to Laravel so I tried to avoid writing obvious questions but I am slightly stuck on this one.
I basically need to create a simple About page and the way I did it is that I created a CRUD module twill:module -BSM abouts
then in the twill-navigation.php
i did the following:
'abouts' => [ 'title' => 'About', 'route' => 'admin.abouts.show', 'params' => [ 'about' => 1 ], ]
It definitely solves my problem but the question is is this the "right" way to do it or will it cause problems down the line? Is there a more elegant way to do this? My frontend will be consumed through graphql and completely detached from the twill/laravel part of the site.
Thank you!
from twill.
Related Issues (20)
- MultiSelect Dropdown out of screen bounds
- Permalink while editing title is different than the permalink shown in the admin
- Axios breaks datatable filters HOT 1
- buttonAsLink option doesn't work on Inline Repeaters
- Unable to use Fieldsets in Block
- Clean Button missing in the Tiptap editor
- [4.x] Refactor capsules and the way all classes are found/inferred HOT 1
- [Feature] Allow packages to register frontend components and package.json for twill:build
- Errors are not reported and displayed on production
- Undefined variable $formBuilder
- Cannot able to add table feature in wysiwyg text editor HOT 1
- Cannot create twill users HOT 7
- Connected fields using the form builder HOT 1
- Time picker js error when `allowInput` is true
- Time and date picker adjusts time based on timezone HOT 1
- Can't unselect option from Select (form field)
- Mediables row gets recreated everytime you save
- Redirected to '/' on reset password
- Unused deprecated dependency in composer.json
- Clicking cancel in the block editor deletes all the unsaved blocks
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from twill.