Conditional or loop statements in rtf template












2















I have predefined rtf template file RTF_Template.rtf as follows:



{rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
{colortbl;red255green0blue0;red0green0blue255;}
widowctrlhyphauto

{pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
{pard ql f0 sa180 li0 fi0 {b UEI:} 103910par}
{pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
{pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
{pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}


I am making changing in this format something like:



rtf_template = Rails.root.join('doc', 'rtf_templates', 'RTF_Template.rtf')
content = File.read(rtf_template)
content.gsub!('FirstName LastName', @student.full_name)
content.gsub!('UEI', StudentIdentifier.primary_identifier.first&.name)
content.gsub!('103910', @student.primary_identifier&.value)
content.gsub!('Female', @student.gender)
content.gsub!('10/31/1980', @student.date_of_birth.strftime('%m-%d-%Y'))
content.gsub!('sample@email.com', @student.email)


Problem:



Currently, I am only showing the first StudentIdentifier which is the primary one on line: content.gsub!('UEI', StudentIdentifier.primary_identifier.first&.name)



and setting value for same identifier on Line: content.gsub!('103910', @student.primary_identifier&.value)



The user can have multiple identifiers and value against that each identifier.
I can access those all identifier using a loop @student.identifiers.each do |p_id|
then identifier name in p_id[0] and value in p_id[1]



I want to show all identifiers on the same place (after name, before sex) in the same template.










share|improve this question



























    2















    I have predefined rtf template file RTF_Template.rtf as follows:



    {rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
    {colortbl;red255green0blue0;red0green0blue255;}
    widowctrlhyphauto

    {pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
    {pard ql f0 sa180 li0 fi0 {b UEI:} 103910par}
    {pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
    {pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
    {pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}


    I am making changing in this format something like:



    rtf_template = Rails.root.join('doc', 'rtf_templates', 'RTF_Template.rtf')
    content = File.read(rtf_template)
    content.gsub!('FirstName LastName', @student.full_name)
    content.gsub!('UEI', StudentIdentifier.primary_identifier.first&.name)
    content.gsub!('103910', @student.primary_identifier&.value)
    content.gsub!('Female', @student.gender)
    content.gsub!('10/31/1980', @student.date_of_birth.strftime('%m-%d-%Y'))
    content.gsub!('sample@email.com', @student.email)


    Problem:



    Currently, I am only showing the first StudentIdentifier which is the primary one on line: content.gsub!('UEI', StudentIdentifier.primary_identifier.first&.name)



    and setting value for same identifier on Line: content.gsub!('103910', @student.primary_identifier&.value)



    The user can have multiple identifiers and value against that each identifier.
    I can access those all identifier using a loop @student.identifiers.each do |p_id|
    then identifier name in p_id[0] and value in p_id[1]



    I want to show all identifiers on the same place (after name, before sex) in the same template.










    share|improve this question

























      2












      2








      2








      I have predefined rtf template file RTF_Template.rtf as follows:



      {rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
      {colortbl;red255green0blue0;red0green0blue255;}
      widowctrlhyphauto

      {pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
      {pard ql f0 sa180 li0 fi0 {b UEI:} 103910par}
      {pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
      {pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
      {pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}


      I am making changing in this format something like:



      rtf_template = Rails.root.join('doc', 'rtf_templates', 'RTF_Template.rtf')
      content = File.read(rtf_template)
      content.gsub!('FirstName LastName', @student.full_name)
      content.gsub!('UEI', StudentIdentifier.primary_identifier.first&.name)
      content.gsub!('103910', @student.primary_identifier&.value)
      content.gsub!('Female', @student.gender)
      content.gsub!('10/31/1980', @student.date_of_birth.strftime('%m-%d-%Y'))
      content.gsub!('sample@email.com', @student.email)


      Problem:



      Currently, I am only showing the first StudentIdentifier which is the primary one on line: content.gsub!('UEI', StudentIdentifier.primary_identifier.first&.name)



      and setting value for same identifier on Line: content.gsub!('103910', @student.primary_identifier&.value)



      The user can have multiple identifiers and value against that each identifier.
      I can access those all identifier using a loop @student.identifiers.each do |p_id|
      then identifier name in p_id[0] and value in p_id[1]



      I want to show all identifiers on the same place (after name, before sex) in the same template.










      share|improve this question














      I have predefined rtf template file RTF_Template.rtf as follows:



      {rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
      {colortbl;red255green0blue0;red0green0blue255;}
      widowctrlhyphauto

      {pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
      {pard ql f0 sa180 li0 fi0 {b UEI:} 103910par}
      {pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
      {pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
      {pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}


      I am making changing in this format something like:



      rtf_template = Rails.root.join('doc', 'rtf_templates', 'RTF_Template.rtf')
      content = File.read(rtf_template)
      content.gsub!('FirstName LastName', @student.full_name)
      content.gsub!('UEI', StudentIdentifier.primary_identifier.first&.name)
      content.gsub!('103910', @student.primary_identifier&.value)
      content.gsub!('Female', @student.gender)
      content.gsub!('10/31/1980', @student.date_of_birth.strftime('%m-%d-%Y'))
      content.gsub!('sample@email.com', @student.email)


      Problem:



      Currently, I am only showing the first StudentIdentifier which is the primary one on line: content.gsub!('UEI', StudentIdentifier.primary_identifier.first&.name)



      and setting value for same identifier on Line: content.gsub!('103910', @student.primary_identifier&.value)



      The user can have multiple identifiers and value against that each identifier.
      I can access those all identifier using a loop @student.identifiers.each do |p_id|
      then identifier name in p_id[0] and value in p_id[1]



      I want to show all identifiers on the same place (after name, before sex) in the same template.







      ruby-on-rails rtf






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 1 at 3:32









      Waqas NazirWaqas Nazir

      557




      557
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Your code simply needs to substitute one placeholder with a sequence of RTF code lines.



          Template:



          {rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
          {colortbl;red255green0blue0;red0green0blue255;}
          widowctrlhyphauto



          {pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
          identifier_list
          {pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
          {pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
          {pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}


          And then concatenate your identifier name / value pairs including the surrounding RTF code, for example



          {pard ql f0 sa180 li0 fi0 {b UEI1:} 103911par}
          {pard ql f0 sa180 li0 fi0 {b UEI2:} 103912par}
          {pard ql f0 sa180 li0 fi0 {b UEI3:} 103913par}


          And finally replace the placeholder



          content.gsub!('identifier_list', myIdentifierListsWithRTF)


          (note: I am no ruby on rails programmer so I can only give the idea, not the actual code)






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992857%2fconditional-or-loop-statements-in-rtf-template%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Your code simply needs to substitute one placeholder with a sequence of RTF code lines.



            Template:



            {rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
            {colortbl;red255green0blue0;red0green0blue255;}
            widowctrlhyphauto



            {pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
            identifier_list
            {pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
            {pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
            {pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}


            And then concatenate your identifier name / value pairs including the surrounding RTF code, for example



            {pard ql f0 sa180 li0 fi0 {b UEI1:} 103911par}
            {pard ql f0 sa180 li0 fi0 {b UEI2:} 103912par}
            {pard ql f0 sa180 li0 fi0 {b UEI3:} 103913par}


            And finally replace the placeholder



            content.gsub!('identifier_list', myIdentifierListsWithRTF)


            (note: I am no ruby on rails programmer so I can only give the idea, not the actual code)






            share|improve this answer




























              0














              Your code simply needs to substitute one placeholder with a sequence of RTF code lines.



              Template:



              {rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
              {colortbl;red255green0blue0;red0green0blue255;}
              widowctrlhyphauto



              {pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
              identifier_list
              {pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
              {pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
              {pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}


              And then concatenate your identifier name / value pairs including the surrounding RTF code, for example



              {pard ql f0 sa180 li0 fi0 {b UEI1:} 103911par}
              {pard ql f0 sa180 li0 fi0 {b UEI2:} 103912par}
              {pard ql f0 sa180 li0 fi0 {b UEI3:} 103913par}


              And finally replace the placeholder



              content.gsub!('identifier_list', myIdentifierListsWithRTF)


              (note: I am no ruby on rails programmer so I can only give the idea, not the actual code)






              share|improve this answer


























                0












                0








                0







                Your code simply needs to substitute one placeholder with a sequence of RTF code lines.



                Template:



                {rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
                {colortbl;red255green0blue0;red0green0blue255;}
                widowctrlhyphauto



                {pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
                identifier_list
                {pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
                {pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
                {pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}


                And then concatenate your identifier name / value pairs including the surrounding RTF code, for example



                {pard ql f0 sa180 li0 fi0 {b UEI1:} 103911par}
                {pard ql f0 sa180 li0 fi0 {b UEI2:} 103912par}
                {pard ql f0 sa180 li0 fi0 {b UEI3:} 103913par}


                And finally replace the placeholder



                content.gsub!('identifier_list', myIdentifierListsWithRTF)


                (note: I am no ruby on rails programmer so I can only give the idea, not the actual code)






                share|improve this answer













                Your code simply needs to substitute one placeholder with a sequence of RTF code lines.



                Template:



                {rtf1ansideff0{fonttbl{f0 fswiss Helvetica;}{f1 Courier;}}
                {colortbl;red255green0blue0;red0green0blue255;}
                widowctrlhyphauto



                {pard ql f0 sa180 li0 fi0 b fs36 FirstName LastNamepar}
                identifier_list
                {pard ql f0 sa180 li0 fi0 {b Sex:u160?}Femalepar}
                {pard ql f0 sa180 li0 fi0 {b DOB:} 10/31/1980par}
                {pard ql f0 sa180 li0 fi0 {b Email:} sample@email.com par}


                And then concatenate your identifier name / value pairs including the surrounding RTF code, for example



                {pard ql f0 sa180 li0 fi0 {b UEI1:} 103911par}
                {pard ql f0 sa180 li0 fi0 {b UEI2:} 103912par}
                {pard ql f0 sa180 li0 fi0 {b UEI3:} 103913par}


                And finally replace the placeholder



                content.gsub!('identifier_list', myIdentifierListsWithRTF)


                (note: I am no ruby on rails programmer so I can only give the idea, not the actual code)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 8 at 19:10









                mjnmjn

                26k22143318




                26k22143318
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992857%2fconditional-or-loop-statements-in-rtf-template%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Mossoró

                    Error while reading .h5 file using the rhdf5 package in R

                    Pushsharp Apns notification error: 'InvalidToken'