نماذج الحقول النائبة

:discourse2: Summary Placeholder Forms will let you build dynamic documentation, by creating a form that replaces any occurrence of a =PATTERN= in your post with the value from a text or selectable input field.
:eyeglasses: Preview Preview on Discourse Theme Creator
:hammer_and_wrench: Repository Link https://github.com/discourse/discourse-placeholder-theme-component
:open_book: New to Discourse Themes? Beginner’s guide to using Discourse Themes

Install this theme component

Features

Add placeholders to posts in this format:

[wrap=placeholder key=NAME description="Your name"][/wrap]
[wrap=placeholder key=COUNTRY default=US defaults=FR,DE,US,CN,AU,CA][/wrap]

Your email: =NAME=-=COUNTRY=@example.com

And this will result in:

This is used in mailing list

Your email: =ZNAME=-=ZCOUNTRY=@example.com

As seen above, text inside the wrapper will be used as a long description.

[wrap=placeholder key=NAME description="Your name"]
This is used in mailing list
[/wrap]

Available keys

  • key: The key that should be replaced in your post
  • default/defaults: default value(s)
  • description: a placeholder text for the input

Examples

# create a new plugin
rails g plugin =PLUGIN_NAME=
cd plugins/=PLUGIN_NAME=

We use it to create runbooks, howtos and reusable templates (it will work in code blocks). Please share your use cases!

Settings

Translation Default
toolbar.builder Add Placeholder
builder.errors.no_key A key is required.
builder.title Add Placeholder
builder.insert Insert
builder.key.label Key
builder.key.description The =Key= to be replaced in the post.
builder.description.label Description
builder.description.description Description displayed on input with no value set.
builder.values.label Default value(s)
builder.values.description Optional value(s) for your placeholder, if multiple values are defined, a select will be used.

:discourse2: Hosted by us? Theme components are available to use on our Standard, Business, and Enterprise plans.

Last edited by @JammyDodger 2024-06-13T22:28:45Z

Check documentPerform check on document:
65 إعجابًا

The big issue with math handling like this, is that you need to eval() and eval is unsafe, so you need to use some lib which provide a safe eval with a limited subset of the real eval. I’m unsure we want all this complexity for such a rare case.

6 إعجابات

I tried ! and that would be a neat composer-preview-redux-in-OP kind of thing but… :pensive: I must be missing something, if I understand correctly the Reply Template component takes the raw and looks for “replacers”, but the Placeholder Forms component decorates the cooked?

What I’m trying to do is ease my users into adding some quizz Q&As in a topic, with minimal technical friction, clicks or even key strokes, :heavy-sigh: :roll_eyes:

[wrap=placeholder key="question" description="question"][/wrap]
[wrap=placeholder key="réponse" description="réponse"][/wrap]

[wrap=template key="template-spoiler" action="reply" tagsList="#qui, #quand, #où, #comment"]

## Question
=question=
### Réponse
[spoiler]
=réponse=
[/spoiler]
---
*Étiquette(s) ?*
[/wrap]

which gives

so far so good, but unfortunately, the placeholders =question= and =réponse= are kept in the composer when hitting the template button

Yes I’m not sure what I was thinking when I wrote this… I probably had a different use case in mind, but can’t remember.

It can’t work this way for sure. I will think a little bit about this… Both theme components were experiments at the time and might deserve better treatment as people have been using it quite frequently.

7 إعجابات

Thank you !

happy lets go GIF by Shalita Grant

3 إعجابات

:grin: I don’t know what’s cookin’ in the chef kitchen, but as I usually stuff myself with pistachios or whatnot while waiting, I managed to make it work (for my specific use of course as I’ve almost no idea of what I’m doing, but hey… :sweat_smile: )

4 إعجابات

Ideally I would like to be able to let admin define their own replacers, but eval is risky (and not even possible with a secure csp) so I’m not sure how I could achieve this…

3 إعجابات

First of all - great and really helpful theme component.

But I think I found a bug. If I use a placeholder in a code snippet, that contains backticks (`), it is not working. An example is a SQL code snippet:

DELETE FROM `=TABLENAME=`
WHERE id NOT IN(
        SELECT
            id FROM (
                SELECT
                    id FROM `=TABLENAME=`
                ORDER BY
                    id DESC
                LIMIT 20
) subquery);

TABLENAME gets never replaced (if there is a TABLENAME placeholder).

سيكون من الرائع لو تضمن هذا أيضًا بعض الشروط الشبيهة بـ Jinja2. بحيث يمكن لشخص ما على سبيل المثال إنشاء مفتاح red وربطه بالرمز :red_circle:، و orange سيتم ربطه بـ :orange_circle:. لكن يمكنني الاستغناء عن ذلك بالطبع، ولكنه كان سيكون رائعًا لو توفرت هذه الشروط التجريبية.

أنا أحب هذا المكون حقًا. :star_struck:


“وأنت تعيش حقًا من أجل =NOUN_1=؟ يا له من حياة =ADJECTIVE_1=!”

“أعيش بها ومعها وعليها وفيها،” قال =PERSON_1=. “إنها أخي وأختي، وعماتي، و =NOUN_2=، وطعام وشراب، و (=ADJECTIVE_2=) =VERBING_1=. إنها =NOUN_3= الخاصة بي، ولا أريد غيرها. ما ليس لديها ليس جديرًا بـ =VERBING_2=، وما لا تعرفه ليس جديرًا بـ =VERBING_3=. يا رب! لقد عشنا =NOUNS_1= معًا! سواء في الشتاء أو الصيف، الربيع أو الخريف، لديها دائمًا =NOUN_4= و =NOUNS_2=. عندما تكون =NOUNS_3= في فبراير، و =NOUN_4= وقبو مليئان بـ =NOUN_5= التي لا تنفعني، و =COLOR_1= =NOUN_6= تجري بجوار أفضل نافذة =NOUN_7= لي؛ أو مرة أخرى عندما يسقط كل شيء =ADVERB_1= ويكشف عن بقع من =NOUN_8= تفوح منها رائحة مثل =FOOD_1=، و =NOUNS_5= و =NOUNS_6= تسد القنوات، ويمكنني أن =VERB_1= حول =MOISTURE= =NOUN_9= فوق معظم =NOUN_10= منها وأجد =FOOD_2= جديدة للأكل، وأشياء =ADJECTIVE_3= أسقطها الناس من =NOUNS_7=!”


الأصل مأخوذ من إصدار الكتب القياسية من الرياح في الصفصاف، متاح لـ قراءته عبر الإنترنت (ابحث عن By it and with it).

10 إعجابات

مرحباً :wave:

شكراً على هذا المكون :heart: إنه يناسب تمامًا ما أحاول تحقيقه الآن. في الواقع، كانت فكرتي الأولى هي أنه سيكون رائعًا إذا كان يمكن دمجه مع مكون Reply Template. ولكن للأسف، هذا غير ممكن كما أوضحت المشاركات أعلاه. :confused:


لقد وجدت حلاً بديلاً لاستخدامه كقالب، ويعمل مع link to new topics و link to new personal messages.

إليك كيف فعلتها:

  1. إنشاء نموذج عنصر نائب (للبساطة، أستخدم المثال في المشاركة الأصلية)

Your email: =NAME=-=COUNTRY=@example.com


  1. إنشاء رابط لموضوع جديد:
    لقد قمت بإعداد الرابط:
  2. category
  3. title
  4. body

إذا كنت ترغب في إضافة أسطر فارغة، استخدم \ حتى لا يتم كسر الرابط أو لجعله غير مرئي يمكنك استخدام   الذي سيضيف مسافة في السطر الجديد. سيكون جزءًا من القالب ويجعل سطرًا فارغًا،

<a href="https://meta.discourse.org/new-topic?category==CATEGORY=&title=This is a topic created by =NAME=&body=Hello :wave:
&nbsp;
This is a test topic... Let's see the placeholder form.
\
Your email: =NAME=-=COUNTRY=@example.com">Use template as new topic</a>

  1. إنشاء معاينة للموضوع

Selected category

=CATEGORY=

Topic title

This is a topic created by =NAME=

Topic body

Hello :wave:

This is a test topic… Let’s see the placeholder form.

Your email: =NAME=-=COUNTRY=@example.com


  1. إنشاء زر “Use template as new topic” (في المثال أعلاه، هذا رابط يمكنك جعله زرًا من هذا)

قم بإنشاء عنصر [wrap] من هذا النص. هذا يجعله متاحًا لاستهدافه باستخدام CSS وتنسيقه. أضيف هذا أدناه.

<a href="https://meta.discourse.org/new-topic?category==CATEGORY=&title=This is a topic created by =NAME=&body=Hello :wave:
&nbsp;
This is a test topic... Let's see the placeholder form.
\
Your email: =NAME=-=COUNTRY=@example.com">[wrap=template-button]Use template as new topic[/wrap]</a>

تنسيق [wrap=template-button]
شيء مثل :arrow_down_small:

Common / CSS

[data-wrap="template-button"] {
  background: var(--tertiary);
  color: var(--secondary);
  border-radius: var(--d-button-border-radius);
  padding: 0.5em 0.65em;
  transition: background 0.25s;
  &:focus,
  &:hover {
    background: var(--tertiary-hover);
    color: var(--secondary);
  }
}

سيبدو زر القالب هكذا :arrow_down_small:

template-button


Demo

Use template as new topic


آمل أن يساعد هذا الدليل الصغير شخصًا يحتاج إلى شيء مشابه :slightly_smiling_face:

تعديل: لقد قمت بإعداد منتقي فئات يضيف القدرة على إنشاء موضوع في فئات مختلفة.


Check the raw version of this post…

8 إعجابات

هذا مذهل يا دون، شكراً لك. هذا يناسب بالفعل أحد احتياجاتي بشكل جيد :slight_smile:

إعجابَين (2)

شيء يجب ملاحظته هو أن كتل التعليمات البرمجية تسبب مشاكل أحيانًا:

usermod -aG sudo =USERNAME=

في هذه الحالة، يفترض highlight.js أن هذا هو Java ويحول كتلة التعليمات البرمجية إلى:


  usermod -
  <span class="hljs-type">aG</span> 
  <span class="hljs-variable">sudo</span> 
  <span class="hljs-operator">=</span>
  USERNAME=

يمكنني إصلاحه عن طريق الإشارة إلى أن هذا في الواقع أمر shell:

    ```shell
    usermod -aG sudo =USERNAME=
    ```

وهذا يؤدي إلى:

usermod -aG sudo =USERNAME=

إذا فشل كل شيء آخر، فإن text يمنع highlight.js من العبث بالعناصر النائبة.

حل أكثر عمومية (يستخدمه Meta Discourse على الأرجح) هو تغيير إعداد لغة التعليمات البرمجية الافتراضية من تلقائي إلى نص عادي أو شيء من هذا القبيل. :wink:


ليس الأمر مهمًا كثيرًا، ولكن استخدام java هو طريقة لتجنب توسيع العنصر النائب عندما تريد الكتابة عن العناصر النائبة.

إعجاب واحد (1)

هل يمكنك التحقق من رابط المعاينة؟ يبدو أنه معطل بالنسبة لي.

إعجاب واحد (1)

هذه ميزة مذهلة، ويمكنني رؤية العديد من الاستخدامات لها.
ومع ذلك، في ردنا، هل من الممكن إخفاء =(name)= حتى يبدأ المستخدم في الكتابة في مربع النص؟ أعتقد أن المستخدمين (خاصة الجدد) قد لا يفهمون الغرض منه، أو قد يبدو أنه تنسيق غير صحيح.

أعتقد أنني حصلت على واحد يعمل مرة أخرى (:crossed_fingers: :slight_smile:)

https://discourse.theme-creator.io/theme/Discourse/placeholder-forms

لقد أضفته أيضًا إلى try.discourse.org حتى تتمكن من اللعب به بشكل عملي. :+1:

إعجاب واحد (1)

ربما يمكنك إدخال قيمة افتراضية ستظهر بدلاً من ذلك.

إعجاب واحد (1)

لقد نجح الأمر! شكراً لك!

إعجابَين (2)

يبدو أن هذا الحل البديل لم يعد يعمل.

هل هناك خيارات أخرى للجمع بين reply-template و #placeholder-forms؟

تم تقسيم 4 مشاركات إلى موضوع جديد: الروابط لا تعمل في نماذج العناصر النائبة