From f8568cd02a6b31f5a904979e10ec5c5cdf66acce Mon Sep 17 00:00:00 2001 From: Yuliya Pazniak Date: Thu, 16 Jan 2025 19:57:15 +0300 Subject: [PATCH 1/2] update fields binding description --- datapress/binding/fields.md | 58 ++++++++++++++++--- .../empty_content_after_custom_field.md | 15 +++++ 2 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 datapress/knowledge_base/devInfo/empty_content_after_custom_field.md diff --git a/datapress/binding/fields.md b/datapress/binding/fields.md index 3403932..dce6175 100644 --- a/datapress/binding/fields.md +++ b/datapress/binding/fields.md @@ -28,20 +28,54 @@ With the Dataverse Integration Fields Binding plugin available in the Addons, yo To use this plugin, follow the steps below: -1. In the Dataverse Admin Area, navigate to Bindings -> Fields Binding. Here, you can set pre-rendering Twig code that will execute before rendering Twig expression substitution. Use this to retrieve data, define variables, and more. -2. Select `Add field` to choose the custom field to display or click `Create field` to create a new custom field. -3. Add a table from which to retrieve data. -4. Click Save. -5. Return to the WordPress Admin Area and create a page. Click `Preferences`, then open the `Panel` settings. -6. Add extra areas to the editor by choosing `Custom fields` option. Click `Enable & Reload` to see the Custom fields section. -7. At the bottom of the page, create a name for custom field(s). Save and publish the page. -8. Go to the pages list, find the page you created and click `Configure Binding` to choose the table to bind and how to bind the post. +1. Navigate to **Bindings -> Fields Binding** in the Dataverse Admin Area: + +- Here, you can set pre-rendering Twig code that will execute before rendering Twig expression substitution. Use this to retrieve data, define variables, and more. + +2. **Create or Add Fields:** + +- Click **Create field** to create a new custom field, then click **Add field** to choose the custom field to display. + +3. **Choose a Table:** + +- Add a table from which to retrieve data. + +4. Click **Save** + +5. Return to the WordPress Admin Area and create a page. + +6. **Enable Custom Fields**: + +- Click **Preferences**, then open the **Panel** settings. Add extra areas to the editor by choosing the **Custom fields** option. Click **Enable & Reload** to see the Custom fields section. + +7. **Select and Add Custom Fields:** + +At the bottom of the page, select the custom field(s) created in the Dataverse Admin Area and click **Add Custom Field**. Use the following example to display the field on the page: + +``` +{{ getMeta("custom_field_name")}}
+``` + +8. **Save and publish** the page. + +9. **Add the output of the meta field to your template:** + +``` +add_filter('integration-cds/twig/functions', function( $functionsArray ) { + $functionsArray['getMeta'] = new TwigFunction('getMeta',function($metaName){ + return get_post_meta(get_the_ID(), $metaName); }); + return $functionsArray;}, 10, 5 ); +``` + +10. **Configure Binding** + +- Go to the pages list, find the page you created, and click **Configure Binding** to choose the table to bind and how to bind the post. Additionally, the following options can replace a field: - **Twig Expression:** Type a Twig expression to display it as the field value. - **Column:** Choose the column logical name from the drop-down. -- **Twig Template:** Choose the Twig template, which can be found under `Templates` -> `Twig Templates`. +- **Twig Template:** Choose the Twig template, which can be found under **Templates** -> **Twig Templates**. - **Formatted Column:** Choose the column logical name from the drop-down. :::note @@ -49,3 +83,9 @@ Additionally, the following options can replace a field: The selected table in the Configure Binding item must match the table for this custom field in the Dataverse Admin Area. ::: + +:::note + +When adding custom fields, you may encounter an empty content of a page. Follow [these steps](/knowledge-base/empty-page-after-custom-field) to resolve the issue. + +::: \ No newline at end of file diff --git a/datapress/knowledge_base/devInfo/empty_content_after_custom_field.md b/datapress/knowledge_base/devInfo/empty_content_after_custom_field.md new file mode 100644 index 0000000..102a465 --- /dev/null +++ b/datapress/knowledge_base/devInfo/empty_content_after_custom_field.md @@ -0,0 +1,15 @@ +--- +title: ERROR Class "TwigFunction" not found +sidebar_position: 21 +slug: /knowledge-base/empty-page-after-custom-field +tags: + - Knowledge base + - DataPress + - TwigFunction + - Fields binding +--- +**Issue:** +When adding custom fields, you may encounter an empty content of a page and see the following error in the logs: `ERROR: Class "TwigFunction" not found`. + +**Solution:** +Add `use Twig\TwigFunction;` to your Theme file. \ No newline at end of file From d67adb73f1b9d3c5b3c68d3b7a81dd5dc3f8df51 Mon Sep 17 00:00:00 2001 From: Yuliya Pazniak Date: Fri, 17 Jan 2025 10:39:26 +0300 Subject: [PATCH 2/2] update fields binding description --- datapress/binding/fields.md | 14 ++++---------- .../devInfo/empty_content_after_custom_field.md | 15 --------------- 2 files changed, 4 insertions(+), 25 deletions(-) delete mode 100644 datapress/knowledge_base/devInfo/empty_content_after_custom_field.md diff --git a/datapress/binding/fields.md b/datapress/binding/fields.md index dce6175..96ffad2 100644 --- a/datapress/binding/fields.md +++ b/datapress/binding/fields.md @@ -61,10 +61,10 @@ At the bottom of the page, select the custom field(s) created in the Dataverse A 9. **Add the output of the meta field to your template:** ``` -add_filter('integration-cds/twig/functions', function( $functionsArray ) { - $functionsArray['getMeta'] = new TwigFunction('getMeta',function($metaName){ - return get_post_meta(get_the_ID(), $metaName); }); - return $functionsArray;}, 10, 5 ); +add_filter('integration-cds/twig/functions', function ($functionsArray) { + $functionsArray['getMeta'] = new Twig\TwigFunction('getMeta', function ($metaName) { + return get_post_meta(get_the_ID(), $metaName); }); + return $functionsArray;}, 10, 5); ``` 10. **Configure Binding** @@ -82,10 +82,4 @@ Additionally, the following options can replace a field: The selected table in the Configure Binding item must match the table for this custom field in the Dataverse Admin Area. -::: - -:::note - -When adding custom fields, you may encounter an empty content of a page. Follow [these steps](/knowledge-base/empty-page-after-custom-field) to resolve the issue. - ::: \ No newline at end of file diff --git a/datapress/knowledge_base/devInfo/empty_content_after_custom_field.md b/datapress/knowledge_base/devInfo/empty_content_after_custom_field.md deleted file mode 100644 index 102a465..0000000 --- a/datapress/knowledge_base/devInfo/empty_content_after_custom_field.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: ERROR Class "TwigFunction" not found -sidebar_position: 21 -slug: /knowledge-base/empty-page-after-custom-field -tags: - - Knowledge base - - DataPress - - TwigFunction - - Fields binding ---- -**Issue:** -When adding custom fields, you may encounter an empty content of a page and see the following error in the logs: `ERROR: Class "TwigFunction" not found`. - -**Solution:** -Add `use Twig\TwigFunction;` to your Theme file. \ No newline at end of file