Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page Metadata #1149

Closed
CSorel-Catalyte opened this issue May 6, 2020 · 7 comments
Closed

Page Metadata #1149

CSorel-Catalyte opened this issue May 6, 2020 · 7 comments
Labels

Comments

@CSorel-Catalyte
Copy link

I have a handful of fields that I would like to add into the manager page settings modal. These will be used by our custom search module for indexing and are not needed to be rendered on the front end. I'd prefer not to extend pagebase or the db schema for that but it's not clear if I can add those as per https://piranhacms.org/docs/extensions/fields to a child class? If so, can I specify that they be rendered in the manager settings modal? I am able to customize the modal partial and js to have a new tab and fields and it posts the field values to the api/page/save/draft endpoint but it's not clear how to persist them to Piranha_PageFields.

I can manually persist those in PageService.Save(PageEditModel model, bool draft), or I can just persist the fields to a separate table in the same method, but it seems like I'm missing something simple here.

Am I approaching this correctly?

@tidyui
Copy link
Member

tidyui commented May 7, 2020

Hi there! Luckily the solution is very simple:

  1. Create a base class for your pages to which you add a region with the fields you need. This will make sure that all pages that inherit from this class gets the region.
  2. In the RegionAttribute for that region, set the property Display to RegionDisplayMode.Setting.

Done!

Regards

@tidyui tidyui added the question label May 7, 2020
@CSorel-Catalyte
Copy link
Author

I knew it had to be something simple. Thanks!

@yiqi0110-glitch
Copy link

Hello, I have something related to this.

    [Field(Placeholder = "")]
    public SelectField<Language> Language { get; set; }

These values are currently being generated through an enum and I would like to have them be generated dynamically from an external source when I open the page edit screen in the manager. Is there a simple solution to this?

@tidyui
Copy link
Member

tidyui commented May 21, 2020

@yiqi0110-glitch The built in SelectField doesn't support this, but I've written a blog article once on how to create this kind of behavior in a custom field that you can take a look at.

https://piranhacms.org/blog/creating-a-custom-tag-field

Regards

@tidyui
Copy link
Member

tidyui commented May 21, 2020

However, this is a good idea that I'll add an issue for.

@yiqi0110-glitch
Copy link

Hello again, I have followed the steps from the blog and I get this issue in the browser console.

piranha-deps-dev.js:16016 [Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.

found in

--->

The code that seems to differ from mine to the example is,

mine (select-field.vue)
`
{{ name }}

<script> export default { props: ["uid", "model", "meta"], methods: { update: function () { if (this.meta.notifyChange) { // Tell parent that value has been updated this.$emit('update-field', { uid: this.uid, title: this.meta.options[this.model.value] }); } } } } </script>`

blog's (custom-tag.vue)
`
{{ item }}

<script> Vue.component("custom-tag", { props: ["uid", "toolbar", "model", "meta"], mounted: function () { var self = this; $("#" + self.uid).select2({ tags: true, selectOnClose: true, placeholder: piranha.resources.texts.addTags }); $("#" + self.uid).on("change", function() { var item = $(this).find("option:selected").text(); self.model.value = item; }); } }); </script>`

Thanks for your time and support.

@tidyui
Copy link
Member

tidyui commented May 22, 2020

Please open a new issue if you need help instead of adding comments to closed issues.

/ Regards

@PiranhaCMS PiranhaCMS locked as resolved and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants