Macro to get Web Part Properties

gourisankar padihary asked on March 13, 2015 08:53

Hi, I have extended, the Link/Button web part to have additional properties as "BackgroundColor", which will have color selector against it, so that user can select any color. Now I want to access this property value in the css styles. I want to have some thing like below:

.applyButton{ background:{%CurrentDocument.GetValue("BackgroundColor","Green")%}; }

But on web part level CurrentDocument is not recognizable, as the above line always returns Green. Can you tell me what could be the macro for accessing the Properties value of Web part. If I have set LinkUrl as "", I want to access this value through macro. Please advice.

Correct Answer

gourisankar padihary answered on March 13, 2015 20:53

Hi, putting style to Web part container does not solve the issue completely as the color applied to web part container. So I have the below code in HTML Envelope for the web part properties and its working :)

  </script type="text/javascript">
     jQuery(function () {
  <//style type="text/css">
        background: {%LinkBackgroundColor%};
        color: {%LinkTextColor%};
0 votesVote for this answer Unmark Correct answer

Recent Answers

Brenden Kehren answered on March 13, 2015 13:15

If you have extended the webpart and added those properties, I'm assuming you added them in the code file as well, correct? If so, then add your logic there for simplicity reasons. If not, I'm not sure your macros will ever work as you have no reference in code to get or set those values so they will always be null.

0 votesVote for this answer Mark as a Correct answer

gourisankar padihary answered on March 13, 2015 13:29

I can access the web part properties like {%LinkBackgroundColor%}. I have not added the property in code behind, as it does not require. I am getting the value what ever I am setting it in Color picker.

Now I need to set this color as background for the Webpart, how can I do inline style for this web part? I have tried web part container, but the following code does not work which I put in Web Part container CSS region:

.applyButton{ background:{%LinkBackgroundColor%}; color:{%LinkTextColor%}; }

0 votesVote for this answer Mark as a Correct answer

Alexander Kontsevoy answered on March 13, 2015 17:26

Hi gourisankar. If you want to set background color for whole web part, do next, please:

  1. Create Web part container
  2. In code section place next code <div style="background: {%ContainerTitle%}">**Web Part**</div>
  3. Open Link/Button Web part properties
  4. In "Web part container" section select your web part
  5. In "Container title" place your color. Like red or #423B8A
  6. press "Save and Close"

Now you can see background for your web part.

If you have access to color variable like this {%LinkBackgroundColor%}, try to put this variable into "Container title" section.

Best regards

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.